[Lazarus] TextHeight in Console App

Howard Page-Clark hdpc at talktalk.net
Tue May 14 16:50:40 CEST 2013


On 14/05/2013 15:32, Graeme Geldenhuys wrote:
> On 2013-05-14 14:07, Edilson Vieira wrote:
>> The project is an Image Generation Program, a console program.
>>
>> The error ocurr when I call the method TextHeight of the Canvas property of
>> TBitmap.
>
> You do realize that if you pull in the 'Graphics' unit of LCL, you don't
> have a console app any more, but a GUI app.
>
> I don't really know what you app does, but I would instead use FPImage
> (from Free Pascal's FCL packages), and use freetype (also included with
> fcl-image code). This will mean your app is not LCL dependent, and a
> real console application.

Or create a Lazarus GUI app and implement Form1's OnCreate handler thus:

procedure TForm1.FormCreate(Sender: TObject);
var bmp: TBitmap;
begin
   bmp := TBitmap.Create;
   try
      bmp.Canvas.Font.Name := 'Tahoma';
      bmp.Canvas.Font.Size := 20;
      bmp.Canvas.Font.Style := [fsBold, fsItalic];
      ShowMessageFmt('Text height is %d',[bmp.Canvas.TextHeight('T')]);
   finally
      bmp.Free;
   end;
end;

For a GUI app Lazarus sets up paths to LCL units such as Graphics (and 
its dependent units) correctly, and includes several such commonly used
units in your uses clause automatically.
Console apps usually require you to manually include the units you use, 
and specify their paths explicitly.




More information about the Lazarus mailing list