对不起我没有完全看清楚你的问题,
参照如下代码(N年前写的,比较烂)
在ONPRINT里调用
function TForm_LineOperationNote.GetOperationStep(const Ticket_id : integer): string;
var
Query: string;
Step_no: integer;
Step_Desc: widestring;
s: widestring;
s1,s2: widestring;
begin
with CDS2do
begin
Close;
Query:='select * from DB2USER.OPTIC_STEP where TICKET_ID='+inttostr(Ticket_id)+' order by STEP_NO';
Provider.DataRequest(Query);
Open;
First;
while not eofdo
begin
Step_no:=fieldbyname('STEP_NO').asinteger;
Step_Desc:=fieldbyname('STEP_DESC').asstring;
s1:= Step_Desc;
if Length(s1)<= 55 then
begin
s:=s+inttostr(Step_no)+' '+Step_Desc+chr(13)+chr(10)+
'-------------------------------------------------------------------------------------------------------------------'
+chr(13)+chr(10);
end;
if Length(s1)>55 then
begin
s1:=copy(Step_Desc,1,55);
s2:=copy(Step_Desc,56,Length(Step_Desc)-55);
s:=s+inttostr(Step_no)+' '+s1+chr(13)+chr(10)+
'-------------------------------------------------------------------------------------------------------------------'
+chr(13)+chr(10)
+' '+s2+chr(13)+chr(10)+
'-------------------------------------------------------------------------------------------------------------------'
+chr(13)+chr(10);
end;
next;
end;
close;
end;
Result := s;
end;