Hello, I am having a bit of a disturbing problem that is leaving me clueless...
I have written a component to display a set of "results", consisting of a name (TEdit), a score (TEdit), and a remark (TMemo). Each result is an instance of a self-written class called TEvaluationLine.
TEvaluationRoster is the wrapping class and actual component, containing methods to manipulate the TEvaluationLines it owns.
TEvaluationRoster has a method called "getPrintableVersion()" which returns a bitmap suited to assign to a Printer Canvas. This method basically asks all the TEvaluationRoster's TEvaluationLines to execute their asBitmap() method, which returns a small bitmap of that specific result, using the paintTo() method of the TEdits and the TMemo to create this bitmap. The TEvaluationRoster then assembles these small bitmaps into a large one and returns it.
Now the problem is that this approach works perfectly under winXp, but for some reason just produces a blank page using win98... Could someone tell me what I'm doing wrong here?
Relevant Code excerpts pasted below.
function TEvaluationLine.asBitmap : TBitMap;
var
smallbmp : TBitMap;
begin
smallBmp := TBitMap.Create;
smallBmp.Width:=TotalWidth;
smallBmp.Height:=Height;
smallbmp.Canvas.Lock;
fCaption.PaintTo(smallbmp.canvas.Handle,0,0);
fEvaluation.PaintTo(smallbmp.canvas.Handle,fCaption.Width,0);
fRemark.PaintTo(smallbmp.canvas.Handle,fCaption.Width+fEvaluation.Width,0);
smallbmp.Canvas.Unlock;
asBitmap:=smallBmp;
end;
function TEvaluationRoster.GetPrintableVersion(inWidth : Integer): TBitMap;
var
scale : double;
smallBmp, bigBmp : TBitMap;
index1,index2 : Integer;
topheight : Integer;
orgHeight:Integer;
begin
orgHeight:=self.Height;
self.ResizeToFitCellHeight;
index1:=0;
index2:=0;
topheight:=0;
bigBmp:=TBitMap.Create;
bigBmp.Width:=inWidth;
scale:=RosterWidth/inWidth;
bigbmp.Height:=Round(RosterHeight/scale);
for index1:=0 to fCols-1 do
begin
topheight:=0;
for index2:=0 to fRows-1 do
begin
smallBmp := fCells[index2,index1].asBitmap;
bigBmp.Canvas.StretchDraw(
Rect(Round(bigbmp.Width*index1/fCols),
topheight,
Round(bigbmp.Width*index1/fCols)+Round(bigBmp.Width/fCols),
topheight+Round(smallbmp.Height/(fCols*scale))
)
,smallBmp);
topheight:=topheight+Round(smallbmp.Height/(fCols*scale));
end;
end;
getPrintableVersion:=bigBmp;
self.Height:=orgHeight;
freeandnil(smallbmp);
end;
procedure TFParent.PrintDiscriminationReport(MyCanvas: TCanvas; Scale: Integer);
var i,x,y,y_start: word;
margin, LongestCol1, LongestCol2, LongestCol3: word;
myClientData: TClientMetaData;
bmp : TBitMap;
oldtab : Integer;
begin
myClientData := GetClientMetaData();
// exit if no clientmetadata!
if not myClientData.Complete then exit;
// Fill canvas:
oldtab:=self.Page.ActivePageIndex;
self.Page.ActivePageIndex:=2;
(...)
bmp:=self.DiscrimStrGrd.getPrintableVersion(printer.PageWidth-20);
mycanvas.Draw(10,y,bmp);
Freeandnil(bmp);
self.Page.ActivePageIndex:=oldtab;
end;
I have written a component to display a set of "results", consisting of a name (TEdit), a score (TEdit), and a remark (TMemo). Each result is an instance of a self-written class called TEvaluationLine.
TEvaluationRoster is the wrapping class and actual component, containing methods to manipulate the TEvaluationLines it owns.
TEvaluationRoster has a method called "getPrintableVersion()" which returns a bitmap suited to assign to a Printer Canvas. This method basically asks all the TEvaluationRoster's TEvaluationLines to execute their asBitmap() method, which returns a small bitmap of that specific result, using the paintTo() method of the TEdits and the TMemo to create this bitmap. The TEvaluationRoster then assembles these small bitmaps into a large one and returns it.
Now the problem is that this approach works perfectly under winXp, but for some reason just produces a blank page using win98... Could someone tell me what I'm doing wrong here?
Relevant Code excerpts pasted below.
function TEvaluationLine.asBitmap : TBitMap;
var
smallbmp : TBitMap;
begin
smallBmp := TBitMap.Create;
smallBmp.Width:=TotalWidth;
smallBmp.Height:=Height;
smallbmp.Canvas.Lock;
fCaption.PaintTo(smallbmp.canvas.Handle,0,0);
fEvaluation.PaintTo(smallbmp.canvas.Handle,fCaption.Width,0);
fRemark.PaintTo(smallbmp.canvas.Handle,fCaption.Width+fEvaluation.Width,0);
smallbmp.Canvas.Unlock;
asBitmap:=smallBmp;
end;
function TEvaluationRoster.GetPrintableVersion(inWidth : Integer): TBitMap;
var
scale : double;
smallBmp, bigBmp : TBitMap;
index1,index2 : Integer;
topheight : Integer;
orgHeight:Integer;
begin
orgHeight:=self.Height;
self.ResizeToFitCellHeight;
index1:=0;
index2:=0;
topheight:=0;
bigBmp:=TBitMap.Create;
bigBmp.Width:=inWidth;
scale:=RosterWidth/inWidth;
bigbmp.Height:=Round(RosterHeight/scale);
for index1:=0 to fCols-1 do
begin
topheight:=0;
for index2:=0 to fRows-1 do
begin
smallBmp := fCells[index2,index1].asBitmap;
bigBmp.Canvas.StretchDraw(
Rect(Round(bigbmp.Width*index1/fCols),
topheight,
Round(bigbmp.Width*index1/fCols)+Round(bigBmp.Width/fCols),
topheight+Round(smallbmp.Height/(fCols*scale))
)
,smallBmp);
topheight:=topheight+Round(smallbmp.Height/(fCols*scale));
end;
end;
getPrintableVersion:=bigBmp;
self.Height:=orgHeight;
freeandnil(smallbmp);
end;
procedure TFParent.PrintDiscriminationReport(MyCanvas: TCanvas; Scale: Integer);
var i,x,y,y_start: word;
margin, LongestCol1, LongestCol2, LongestCol3: word;
myClientData: TClientMetaData;
bmp : TBitMap;
oldtab : Integer;
begin
myClientData := GetClientMetaData();
// exit if no clientmetadata!
if not myClientData.Complete then exit;
// Fill canvas:
oldtab:=self.Page.ActivePageIndex;
self.Page.ActivePageIndex:=2;
(...)
bmp:=self.DiscrimStrGrd.getPrintableVersion(printer.PageWidth-20);
mycanvas.Draw(10,y,bmp);
Freeandnil(bmp);
self.Page.ActivePageIndex:=oldtab;
end;