主从表中如何在从表中动态给各字段排序?(200分)

  • 主题发起人 主题发起人 fqhome
  • 开始时间 开始时间
F

fqhome

Unregistered / Unconfirmed
GUEST, unregistred user!
我在从表中是用的以下过程:
procedure TForm1.MySort(DBGrid0:TDBGrid; Column: TColumn);
var
//本模块使用到的psIndexName, plAscend两个变量见上定义
mode:char; //记录是“升序”还是“降序”
ColName:string; //记录当前字段名
iCol:Integer; //记录当前列号
begin
with DBGrid0.DataSource.DataSet as TTable do //Table0
begin
//检测当前工作表是否已打开
if not Active
then begin
MessageBeep(0);
Application.MessageBox('工作表尚未打开!','停止',MB_OK+MB_ICONSTOP);
Abort
end;
//检测当前字段是否“能排序”。以下字段类型不能排序
case Column.Field.DataType of
ftBoolean,
ftBytes,
ftBlob, //Binary
ftMemo,
ftGraphic,
ftFmtMemo, //Formatted memo
ftParadoxOle: //OLE
begin
MessageBeep(0);
Application.MessageBox(Pchar('项目'''+Column.FieldName+''''+'不能排序!'),'停止',MB_OK+MB_ICONSTOP);
Abort
end;
end; //case
mode:='0';
iCol:=Column.Field.FieldNo-1;
try
ColName:=Column.fieldname;
if psIndexName=Column.fieldname
then begin //与原来同列
if plAscend //升序
then begin
mode:='2';
IndexName:=ColName+'2'; //应“降序”
end
else begin
mode:='1';
IndexName:=ColName+'1'; //应“升序”
end;
plAscend:=not plAscend;
end
else begin //新列
IndexName:=ColName+'2';
plAscend:=false;
psIndexName:=ColName;
end;
except
on EDatabaseError do //若未有索引,则重新建立
begin
Messagebeep(0);
//以下新建索引
IndexName:='';
Close;
Exclusive:=true;
if mode='1'
then AddIndex(ColName+'1',ColName,[ixCaseInsensitive],'')//
else //包括'0'
AddIndex(ColName+'2',ColName,[ixDescending,ixCaseInsensitive],'');
Exclusive:=false;
Open;
try //try 1
if mode<>'1'
then begin
mode:='2';//转换
plAscend:=false;
end
else plAscend:=true;
IndexName:=ColName+mode;
psIndexName:=ColName;
except
on EDBEngineError do
IndexName:='';
end //try 2
end
end;
First;
end; //with
DBGrid0.SelectedIndex:=iCol;
end;
可是,一排序从表的dbgrid就空了,我不知如何才能实现这个功能,help!SOS
楼上的大哥大姐救命:(
 
没有对dbgrid做刷新,建议用sql语句的order by dec简单且不容易出错。
 
我用table.refresh刷新了,还是不行。
 
顺便说一句,我原来用它来排序非主从结构很成功,不知道是不是因为主从结构不能改
索引字段的原因,如果是的话,我看table是实现不了这个功能了。
欢迎继续讨论,参加者都会视情况给分。
 
看来没有答案了,能不能给chwa 50分,剩下的还给我?
 
这样送出200分太亏了,我怎么这么大方?!下回要省点花了555555555
干脆借这个地方再发个问题吧,150分
请问在三层结构中如何设置web服务器?
假设我已经做好了企业对象。
 
后退
顶部