在 Ehlib 中, 如何在 PrintDBGridEh 的 BeforeGridText 属性中引用自定义变量 ?(100分)

M

mblk

Unregistered / Unconfirmed
GUEST, unregistred user!
在 Ehlib 中, 如何在 PrintDBGridEh 的 BeforeGridText 属性中引用自定义变量? 如何
定义这个变量?
 
好久没有用ehlib了,不知道对不对
PrintDBGridEh1.BeforeGridText.Text

PrintDBGridEh1.BeforeGridText.add

PrintDBGridEh1.BeforeGridText.LoadFromFile()
或。。。。。
 
直接引用就行了,我就这么用:
PrintDBGrid1.BeforeGridText.Clear;
PrintDBGrid1.BeforeGridText.Append('病人姓名:'+DBGridEh1.Fields[4].AsString+' 收费时间:'+datetimeToStr(DBGridEh1.Fields[0].AsDateTime)+' 收费操作员:'+DBGridEh1.Fields[1].AsString+' 就诊号:'+DBGridEh1.Fields[2].AsString+' 单据号:'+DBGridEh1.Fields[3].AsString);
 
像这样:比如你的BeforeGridText为%[today],你可以写这样的代码
S:=Datetostr(Now);
PrintDBGridEh1.Set_Substitutes(['%[today]', S]);
 
这个问题我正好不久前研究过,呵呵。。。 楼上几位说的都不错,不过,不够完美。
我用的EHLIB 2.5中,BeforeGridText有一个重要特性,就是他是RTF格式的,表头设计能
用上RTF,并且是可视化的,实在是很爽,不过如何做到动态的表头呢?
我开始想到用格式化字符串,但是直接对RTF文本进行format后,发现RTF属性丢失,后来
利用LoadFromStream,SaveToStream来处理RTF字节流才解决了问题。。。现在写成了一个
函数: FormatRTF,可以在表头中输入格式化字符串,并保持格式不变。
 
LuJuhe,能否再详细些?
 
FormatRTF过程如下:
procedure FormatRTF(rtf: TStrings; const fmt: array of const);
var
tmpStream: TStringStream;
tmpRTF: TStrings;
begin
tmpStream := TStringStream.Create('');
try
tmpRTF := TStringlist.Create;
try
rtf.SaveToStream(tmpStream);
tmpStream.Position := 0;
tmpRTF.LoadFromStream(tmpStream);
tmpRTF.Text := Format(tmpRTF.Text,fmt);
tmpStream.Position := 0;
tmpRTF.SaveToStream(tmpStream);
tmpStream.Position := 0;
rtf.LoadFromStream(tmpStream);
finally
tmpRTF.Free;
end;
finally
tmpStream.Free;
end;
end;

procedure RestoreRTF(rtf: TStrings; tortf: TStrings);
var
tmpStream: TStringStream;
begin
tmpStream := TStringStream.Create('');
try
rtf.SaveToStream(tmpStream);
tmpStream.Position := 0;
tortf.LoadFromStream(tmpStream);
finally
tmpStream.Free;
end;
end;

调用方法:
procedure TfrmSpec.btnPrintClick(Sender: TObject);
begin
with PrintDBG do begin
RestoreRTF(tmpRTF,BeforeGridText);
FormatRTF(BeforeGridText,[cmboxCX.Text,cmboxND.Text,cmboxYF.Text,cmboxJEDW.Text]);
Preview;
end;
end;
其中tmpRTF是一个变量,用于保存包含了格式信息的RTF字符串,以免多次预览时不能格式化了。
 
LuJuhe,我在程序中加了以下两条语句后,运行程序就出错,为什么?
ss:='dadsada';
tmprtf.text:=ss;
 
前后语句没贴出来?
大概是你的tmprtf没有初始化获得内存吧。
tmprtf := TStringList.Create(self);
tmprtf.text := ss;
.......
 
LuJuhe,加入语句 tmprtf := TStringList.Create(self)后,编译显示
Too many actual parameters
 
编译错误。。。 你自己解决吧,呵呵。。。

(TStringList.Create,没有参数)
 
如何解决
 
改成TStringList.Create;

... 唉,看来以后还是得说清楚点。
 
LuJuhe, cmboxCX,cmboxND,cmboxYF,cmboxJEDW是干什么用的
 
顶部