中文折行老问题送分了~~~~~~~(100分)

  • 主题发起人 主题发起人 myth0316
  • 开始时间 开始时间
M

myth0316

Unregistered / Unconfirmed
GUEST, unregistred user!
我的quickreport是QuickReport.v4.5.for.Delphi7 带原码的,为了解决中文折行的问题,我是这样操作的:
第一步:
先安装quickreport 然后在.../Delphi7/lib目录下,找到qrctrls.dcu,删除之或改名,将.../Delphi7/quickrpt
目录下的qrctrls.pas和qrdefs.inc两个文件copy到.../Delphi7/lib目录下,然后将
qrdefs.inc中的
//{$DEFINE VER110}
一句改为
{$DEFINE VER100}
第二步:
然后在qrctrls.pas中找到TQRCustomLabel.FormatLines过程,将其修改如下:
procedure TQRCustomLabel.FormatLines;
var
I, J : integer;
NewLine : string;
LineFinished : boolean;
HasParent : boolean;
MaxLineWidth : integer;
AAlignment: TAlignment;
function aLineWidth(Line : string) : integer;
begin
if HasParent then
result := Muldiv(Longint(ParentReport.TextWidth(Font, Line)),Zoom,100)
else
Result := Canvas.TextWidth(Line);
end;

procedure FlushLine;
begin
FFormattedLines.Add(NewLine);
NewLine := '';
end;

procedure AddWord(aWord : string);
//{$ifdef ver100}
var
S: string;
//{$endif}
begin
if aLineWidth(NewLine + aWord) > Width then
begin
if NewLine = '' then
begin
//{$ifdef ver100}
if SysLocale.FarEast then
begin
while truedo
begin
if (aWord[1] in LeadBytes) and (Length(aWord) > 1) then
S := copy(aWord, 1, 2)
else
S := copy(aWord, 1, 1);
if aLineWidth(NewLine + S) < Width then
begin
NewLine := NewLine + S;
Delete(aWord, 1, Length(S));
end
else
Break;
end;
end
else
while aLineWidth(NewLine + copy(aWord, 1, 1)) < Widthdo
begin
NewLine := NewLine + copy(aWord, 1, 1);
Delete(aWord, 1, 1);
end;
//{$else
}
// while aLineWidth(NewLine + copy(aWord, 1, 1)) < Widthdo
// begin
// NewLine := NewLine + copy(aWord, 1, 1);
// Delete(aWord, 1, 1);
// end;
//{$endif}
aWord := '';
end;
FlushLine;
if aLineWidth(aWord) > Width then
begin
if NewLine = '' then
begin
if Width = 0 then
aWord := ''
else
while aLineWidth(aWord) > Widthdo
//{$ifdef ver100}
if ByteType(aWord, Length(aWord)) = mbTrailByte then
Delete(aWord, Length(aWord)-1, 2)
else
//{$endif}
Delete(aWord, Length(aWord), 1);
end;
NewLine := aWord;
FlushLine;
aWord := '';
end;
if not WordWrap then
begin
aWord := '';
LineFinished := true;
end;
end;
NewLine := NewLine + aWord;
end;

procedure AddLine(Line : string);
var
aPos : integer;
begin
while pos(#10, Line) > 0do
Delete(Line, Pos(#10, Line), 1);
aPos := pos(#13, Line);
if aPos > 0 then
begin
repeat
AddLine(copy(Line, 1, aPos - 1));
Delete(Line, 1 , aPos);
aPos := pos(#13, Line);
until aPos = 0;
AddLine(Line);
end else
begin
J := 0;
NewLine := '';
LineFinished := false;
if AutoSize then
begin
NewLine := Line;
FlushLine;
LineFinished := True;
end else
begin
while (J < Length(Line)) and (Length(Line) > 0)do
begin
repeat
//{$ifdef ver100}
begin
inc(J);
if Line[J] in LeadBytes then
begin
inc(J);
break;
end;
end;
//{$else
}
// inc(J)
//{$endif}
until (Line[J] in BreakChars) or (J >= Length(Line));
AddWord(copy(Line, 1, J));
Delete(Line, 1, J);
J := 0;
end;
if not LineFinished then
FlushLine;
end;
end;
end;

procedure FormatFromCaption;
begin
AddLine(FPrintCaption);
if not UpdatingBounds and HasParent then
begin
UpdatingBounds := true;
if Height < (longint(ParentReport.TextHeight(Font, 'W') * Zoom div 100) + 1) then
Height := (longint(ParentReport.TextHeight(Font, 'W')) * Zoom div 100) + 1;
UpdatingBounds := false;
end
end;

procedure FormatFromStringList;
var
J : integer;
begin
if (FLines.Count <> 0) then
begin
if AutoSize then
FFormattedLines.Assign(FLines)
else
for J := 0 to FLines.Count - 1do
AddLine(FLines[J]);
end else
if csDesigning in ComponentState then
begin
FCaption := Name;
FormatFromCaption;
FCaption := '';
end;
end;

begin
if Parent <> nil then
begin
if assigned(FFormattedLines) then
FFormattedLines.Clear
else
FFormattedLines := TStringList.Create;
HasParent := ParentReport <> nil;
LineFinished := false;
if CaptionBased then
FormatFromCaption
else
FormatFromStringList;
if AutoSize and (not UpdatingBounds) and HasParent then
begin
MaxLineWidth := 0;
for I := 0 to FFormattedLines.Count - 1do
if aLineWidth(FFormattedLines) > MaxLineWidth then
MaxLineWidth := aLineWidth(FFormattedLines);
if Frame.DrawLeft then
MaxLineWidth := MaxLineWidth + Frame.Width;
if Frame.DrawRight then
MaxLineWidth := MaxLineWidth + Frame.Width;
UpdatingBounds := true;
AAlignment := Alignment;
// {$ifdef ver110}
if UseRightToLeftAlignment then
ChangeBiDiModeAlignment(AAlignment);
// {$endif}
case AAlignment of
taCenter : Left := Left + ((Width - MaxLineWidth) div 2);
taRightJustify : Left := Left + Width - MaxLineWidth;
end;
Width := MaxLineWidth;
if (FFormattedLines.Count = 0) and (csDesigning in ComponentState) then
Height := (longint(ParentReport.TextHeight(Font, 'W')) * Zoom div 100) + 1;
if (Height < (longint(ParentReport.TextHeight(Font, 'W') * Zoom div 100) + 1)) then
Height := (longint(ParentReport.TextHeight(Font, 'W')) * Zoom div 100) + 1;
UpdatingBounds := false;
end;
end;
do
neFormat := true;
end;
然后再在 component-install packages -add -dclqrt70.bpl
前一阵我用这种方法成功的解决了折行问题并且作了数个报表,但是昨天重装了系统后再按上述方法将quickreport装上,发现原来做的报表不能折行了,有高手帮忙解决吗??在此送分100
 
用 Grid++Report 根本不用编程序。
 
后退
顶部