On Sun, 10 Oct 2010 17:52:46 +0200, Sven Barth
<[email protected]> wrote:
>> (I.e. can one enter compiler directives condistioned on other things
>> in an ifdef construct?)
>>
>Yes, that is perfectly legal and even necessary if you use multiple
>compilers.
>You can also write all those settings into an *.inc file and just
>include that at the top of your unit (e.g. {$I compilerswitches.inc});
>this works in both FPC and Delphi and so you have the same settings in
>all your units where you include that file (of course you need to
>include the {$ifdef fpc} inside the include file).
Well, it seems like there are more conditionals needed in a multi-use
unit. For example there is no place for units Windows and Variants on
Lazarus and there are Lazarus units that Delphi doesn't like.
So I have first let Lazarus adjust my Delphi project and then I have
examined the differences and put in conditionals for FPC so that the
code passes through Delphi just like before.
But then I have encountered a lot of problems in a graphics class I
created years ago to plot simple diagrams on a TImage Canvas.
Apparently a *lot* of properties and methods pertaining to the TImage
Canvas are defined in unit Windows, which must not be used with
Lazarus...
So how can I get the darn graphics working in Lazarus and Delphi?
I thought that the image canvas was somehow dealt with in Lazarus so
it could be used just like in Delphi. Mind you, I am not doing rocket
science with my graphics class, I just made it able to plot using
floats as coourdinates and the shapes plotted are lines, circles,
boxes and the like plus text.
Here is an example method that bombs:
function TGraphImage.TiltedText(X1, Y1, A: double; sText: string):
boolean;
var
lf : {$IFNDEF FPC} TLogFont {$ELSE} TFont {$ENDIF};
tf : TFont;
nX, nY, nH: integer;
begin
Result := false;
if not Assigned(FPlotImage) then exit;
with FPlotImage.Canvas do
begin
nH := Font.Height;
nX := Round((X1-FOffsX) * FScaleX);
nY := Round((FOffsY-Y1) * FScaleY) + nH;
tf := TFont.Create;
tf.Assign(Font);
GetObject(tf.Handle, sizeof(lf), @lf);
lf.lfEscapement := Round(A*10);
lf.lfOrientation := Round(A*10);
tf.Handle := CreateFontIndirect(lf);
Font.Assign(tf);
Brush.Style := bsClear;
TextOut(nX-nH, nY, sText);
{Reset orientation}
lf.lfEscapement := 0;
lf.lfOrientation := 0;
tf.Handle := CreateFontIndirect(lf);
Font.Assign(tf);
tf.Free;
end;
Result := true;
end;
Lazarus does not like TLogFont and I found it came from Windows so I
put a conditional there. But it only stepped to the next error:
GetObject is apparently a Windows defined method as well....
And on it goes (lfEscapement, lfOrientation, Handle,
CreateFontIndirect).
(By the way I tried to indent the code example using settings that
should put spaces in there but as you can see the indentation is by
TAB chars instead...
Bo Berglund
--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus