挑战问题的进来。(20分)

B

beckzd

Unregistered / Unconfirmed
GUEST, unregistred user!
帮我看看下面的代码什么意思。
procedure gridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var cy,cx:integer;
txt:String;
style:string;
i,j,k:integer;
R,D,L,U:integer;
TxtLeft,TxtTop,TxtBottom,TxtRight:integer;
MyREct:Trect;
function GetCol(Acol,Arow:integer):String;
var i:integer;
Mypos:integer;
MyString:String;
begin
MyString:=TSTringGrid(Sender).cells[acol,0];
for i:=0 to Arow do
begin
myPos:=pos('|',MyString)-1;
if Mypos<0 then
begin
REsult:=MyString;
exit;
end;
if pos('|',MyString)<>1 then
Result:=copy(MyString,1,Mypos);
Mystring:=copy(Mystring,Mypos+2,length(MyString));
end;
end;
 
首先你的程序没粘贴完
这段程序在gridDrawCell过程中又定义了一个专用的过程

procedure gridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var cy,cx:integer;
txt:String;
style:string;
i,j,k:integer;
R,D,L,U:integer;
TxtLeft,TxtTop,TxtBottom,TxtRight:integer;
MyREct:Trect;
function GetCol(Acol,Arow:integer):String;//这个函数只能在gridDrawCell事件中使用
var i:integer;
Mypos:integer;
MyString:String;
begin
MyString:=TSTringGrid(Sender).cells[acol,0];
for i:=0 to Arow do
begin
myPos:=pos('|',MyString)-1;//判断MyString中'|'的位置,减一可能是‘|’的位置不能是首字符
if Mypos<0 then
begin
REsult:=MyString; //如果不包含或在首字符则返回Mystring
exit;
end;
if pos('|',MyString)<>1 then
Result:=copy(MyString,1,Mypos);//如果包含了,则返回第一字符到‘|’之间的字符串
Mystring:=copy(Mystring,Mypos+2,length(MyString));将mystring字符串更改为‘|’之后的字符串
end;
end;

 
谢谢snappy ,还想问问你,你指的程序没有贴完什么意思,
我 是把这个过程的代码都贴出来了,
然后别的unit引用了这个函数。还想问问你。他为什么老是要判断‘|’字符啊,
在显示的字符串中并没有这个字符的。为什么要以这个为判断啊。
 
可能是为了实现 cell 的 hint ,
AAAAA|BBBBB
 
代码没贴完,可能是实现一个取指定列最后一行的什么数据。关键是看Cells[col,0]保存的是什么数据了。
 
多人接受答案了。
 
grid赋值的问题
 
多人接受答案了。
 
顶部