Virtual Treeview中CreateEditor定制需要几步?

王朝delphi·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

DataVerifyer 中create a editor for 'for' 需要记下几步:

1。将sky和ostr(要edit的text)传入改写后的TStringEditLink中

procedure TScriptsForm.DataTreeCreateEditor(Sender: TBaseVirtualTree;

Node: PVirtualNode; Column: TColumnIndex; out EditLink: IVTEditLink);

var

skey,ostr: string;

begin

if DataTree.FocusedNode = nil then

exit;

if DataTree.FocusedNode.Index=0 then

exit;

ostr := DataTree.Text[DataTree.FocusedNode,0];

//******************************************

if LowerCase(LeftStr(Trim(ostr),3))='for' then

begin

ostr := StringReplace(ostr, 'for(i=0;IsRuning&&i<', '', [rfReplaceAll]);

ostr := StringReplace(ostr, ';i++);', '', [rfReplaceAll]);

skey:='for';

end

//*******************************************

else

begin

ostr := GetKeyOfFuction(ostr, skey);

ostr := StringReplace(ostr, '''', '', [rfReplaceAll]);

ostr := StringReplace(ostr, '"', '', [rfReplaceAll]);

end;

EditLink:= TStringEditLink.Create(skey,ostr);

end;

2。//设置bounds的偏移,使得editor显示时正好在要edit的text上

procedure TStringEditLink.SetBounds(R: TRect);

// Sets the outer bounds of the edit control and the actual edit area in the control.

var

Offset: Integer;

exOffset:Integer;

begin

if not FStopping then

begin

if Fkey<>'' then

begin

//****************************

if LowerCase(LeftStr(Trim(Self.FTree.GetText(FNode ,FColumn)),3))='for' then

exOffset:=Self.FTree.Canvas.TextWidth('for(i=0;IsRuning&&i<')

// ***************************

else

begin

if ( Pos(',',Self.FTree.GetText(FNode ,FColumn))=0 )and ( Pos('(',Self.FTree.GetText(FNode ,FColumn))<>0) then

exOffset:=Self.FTree.Canvas.TextWidth('Agent.'+Fkey+'(')+2;

if ( Pos(',',Self.FTree.GetText(FNode ,FColumn))=0 )and ( Pos('"',Self.FTree.GetText(FNode ,FColumn))<>0) then

exOffset:=Self.FTree.Canvas.TextWidth('Agent.'+Fkey+'="')+2;

end;

…………………………………………

end;

3。//重绘,使得用户不会觉察不用edit的文本的改变

procedure TScriptsForm.DataTreeAfterCellPaint(Sender: TBaseVirtualTree;

TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;

CellRect: TRect);

var

R:TRect;

twidth:Integer;

skey,ostr,temp: string;

begin

if tsEditing in Sender.TreeStates then

if Sender.FocusedNode=Node then

begin

ostr := DataTree.Text[DataTree.FocusedNode,0];

temp:=ostr ;

ostr := GetKeyOfFuction(ostr, skey);

R:=Sender.EditLink.GetBounds;

//************************************************

if (LowerCase(LeftStr(Trim(temp),3))='for') then

begin

twidth:=TargetCanvas.TextWidth('for(i=0;IsRuning&&i<');

TargetCanvas.TextOut(R.Left-twidth,CellRect.Top+2,'for(i=0;IsRuning&&i<');

TargetCanvas.TextOut(r.Right+1,CellRect.Top+2,';i++);');

Exit;

end;

//**************************************************

if ( Pos(',',temp)=0 )and ( Pos('(',temp)<>0) then

begin

twidth:=TargetCanvas.TextWidth('Agent.'+skey+'(');

TargetCanvas.TextOut(R.Left-twidth, CellRect.Top + 2, 'Agent.'+skey+'(');

TargetCanvas.TextOut(R.Right+1, CellRect.Top + 2, ');');

Exit;

end;

if ( Pos(',',temp)=0 )and ( Pos('"',temp)<>0) then

begin

twidth:=TargetCanvas.TextWidth('Agent.'+skey+'="');

TargetCanvas.TextOut(R.Left-twidth, CellRect.Top + 2, 'Agent.'+skey+'="');

TargetCanvas.TextOut(R.Right+1, CellRect.Top + 2, '";');

Exit;

end;

end;

end;

4。//对newtext进行格式设置,检查数据是否正确,并写到储存datatree的stringlist中

procedure TScriptsForm.DataTreeNewText(Sender: TBaseVirtualTree;

Node: PVirtualNode; Column: TColumnIndex; NewText: WideString);

var

ind: Integer;

skey,ostr,temp: string;

begin

ind := Node.Index;

ostr:=stringlist[ind];

temp:=ostr ;

ostr := GetKeyOfFuction(ostr, skey);

skey:=Trim(lowerCase(skey));

if skey = 'wapgateway' then ;

if skey = 'protocol' then

begin

if (lowerCase(trim(NewText)) <>'co') and (lowerCase(trim(NewText)) <>'cl') and (lowerCase(NewText) <>'http') then

begin

ShowMessage('You should select one of CO,CL,and HTTP as the Protocol!' );

Exit;

end;

end;

if skey = 'pause' then

begin

if (StrToInt(trim(NewText))>=0) and (StrToInt(trim(NewText))<=1000) then

else

begin

ShowMessage('You should input the time between 0 and 1000!' ) ;

Exit;

end;

end;

if skey = 'readsms' then ;

if skey = 'readmms' then ;

//***********************************************************

if LowerCase(LeftStr(Trim(temp),3))='for' then

begin

if (StrToInt(trim(NewText))>=0) and (StrToInt(trim(NewText))<=1000) then

stringlist[ind] :='for(i=0;IsRuning&&i<'+trim(NewText)+';i++);'

else

begin

ShowMessage('You should input the time between 0 and 1000!' ) ;

Exit;

end;

end

//**********************************************************

else

begin

if (Pos(',',temp)=0 )and (Pos('(',temp)<>0) then

stringlist[ind] := 'Agent.'+skey+'('+trim(NewText)+');';

if (Pos(',',temp)=0 )and (Pos('"',temp)<>0) then

stringlist[ind] := 'Agent.'+skey+'="'+trim(NewText)+'";';

end;

Sender.RepaintNode(Node);

end;

飞飞于北京

2005-8-18 am

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航