> Bj?rge S?ther <REMOVE_bsaether@THIS_online.no> wrote in message
> news:zZcy5.4935$mq2.81248@news1.online.no...
> > "David Reeve" <drscienti...@powerup.com.au> skrev i melding
> > news:39c8901f@grissom...
> > > If I map a logical font to a HFONT called hfNewFont, and test it with
> > two
> > > buttons as follows,
> > > procedure TForm1.Button1Click(Sender: TObject);
> > > begin
> > > SelectObject(canvas.Handle, hfNewFont);
> > > TextOut(canvas.handle, 200, 200, 'Testline', 8);
> > > end;
> > > procedure TForm1.Button2Click(Sender: TObject);
> > > begin
> > > TextOut(canvas.handle, 200, 200, 'Testline', 8);
> > > end;
> > > Button 1 displays the new font OK, but button 2 always displays the
> > original
> > > font, even if it is hit second.
> > > With a bit of messing around, it is seems that if the program returns
> > to the
> > > application message loop, the original font is remapped to the canvas
> > device
> > > context.
> > > I feel I missing something that I should know, but what?
> > I would call what you're doing is a bit "anti-VCL-like", and you will
> > see some pretty odd sideeffects. The TFont class is nothing ut a wrapper
> > around a Windows font object, but it actually keeps the data in it's own
> > fields, it doesn't use Windows' own values. When you set the forn handle
> > of the Canvas by a SelectObject, Canvas.Font.Handle and Selected HFONT
> > in Canves.Handle (HDC) isn't the same anymore. At the first occasion
> > where the TCanvas object needs to get its handles "refreshed", it will
> > restore the previous font.
> > What you should rather do, I guess:
> > Canvas.Font.Handle:=hfNewFont;
> > ...now I believe it will keep looking the same...;-)
> > --
> > Bjoerge Saether
> > Consultant / Developer
> > Asker, Norway
> > bsaether.removet...@online.no (remove the obvious)
> Thanks...... thats a much better solution as it keeps the VCL happy.
Also,
> the VCL frees up the replaced HFONT object for you.
> However, I have come across an instability when I'm doing all this font
> modifying stuff. Basically, the problem seems to lie with the definition
of
> Window's LOGFONT versus Delphi's TLogfont structures.
> If I do something like,
> var
> tempFont: TLogfont;
> begin
> GetObject(canvas.font.handle, SizeOf(tempFont), @tempFont);
> with tempFont do
> begin
> lfEscapement := 900;
> lfOrientation := 900;
> end;
> canvas.font.handle := CreateFontIndirect(tempFont);
> end;
> The results are unpredictable, and it seems to depend upon what was in the
> piece of memory @tempFont. For insatnce, if you fill this block before
> calling GetObject like so,
> FillChar(tempFont, SizeOf(tempFont),0)
> the results vary according to what you fill it with!
> Has anyone come across this?
> regards
> Dave