L
liuly
Unregistered / Unconfirmed
GUEST, unregistred user!
找一个带源码的QR,我是用QR3.5 for D6试验的,别的版本应该也可以,您可以试试看
第一步:
在.../Delphi6/lib目录下,找到qrctrls.dcu,删除之或改名,将.../Delphi6/quickrpt
目录下的qrctrls.pas和qrdefs.inc两个文件copy到.../Delphi6/lib目录下,然后将
qrdefs.inc中的
//{$DEFINE VER100}
一句改为
{$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;
呵呵,其实就是加几个“//”啦。
如果还不行,将borland目录下所有的qrctrls.dcu都删掉试试。其实应该做完第一步就
行了,但是我在QR3.5中试验不成功,不知道别的版本如何,可以的话,请说一声吧。
Good Luck !
第一步:
在.../Delphi6/lib目录下,找到qrctrls.dcu,删除之或改名,将.../Delphi6/quickrpt
目录下的qrctrls.pas和qrdefs.inc两个文件copy到.../Delphi6/lib目录下,然后将
qrdefs.inc中的
//{$DEFINE VER100}
一句改为
{$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;
呵呵,其实就是加几个“//”啦。
如果还不行,将borland目录下所有的qrctrls.dcu都删掉试试。其实应该做完第一步就
行了,但是我在QR3.5中试验不成功,不知道别的版本如何,可以的话,请说一声吧。
Good Luck !