3

I'm working on using win api for delphi. I tried with DrawString procedure for over couple hours, but still can't get it right. Delphi keep gives me the message 'there is no overload version of 'DrawString' that can be called with these arguements'. I've tried on a form and on a custompanel to write messages...

uses
WinApi.Windows, WinApi.Messages, System.SysUtils, System.Classes, Vcl.Dialogs,
System.DateUtils,
WinApi.GDIPApi,
WinApi.GDIPObj,
Vcl.Forms, Vcl.Controls, Vcl.Graphics,
dxSkinsCore, dxSkinsDefaultPainters, cxGraphics, cxControls, cxLookAndFeels,
cxLookAndFeelPainters, cxContainer, cxEdit, cxGroupBox, cxCheckGroup,
Data.DB, SHIS.Dataset, Datasnap.DBClient, cxTextEdit, cxDBEdit,
cxImageComboBox, Vcl.Menus, cxCheckBox, Vcl.StdCtrls,
cxMaskEdit, cxDropDownEdit,
cxCheckComboBox, SHIS.Editor, cxButtons, SHIS.Ctrl, SHIS.ExtCommCdControl;

type
 TCommCdF = class(TForm)
 btn4: TButton;
 procedure btn4Click(Sender: TObject);
private
protected
public
 constructor Create(AOwner: TComponent); override;
 destructor Destroy; override;

procedure InitParams; override;
end;

implementation

{$R *.dfm}

uses

procedure TCommCdF.btn4Click(Sender: TObject);
 var
 testgraphics : TGPGraphics;
 testPen : TGPPen;
 testBrush : TGPSolidBrush;
 testFont : TGPFont;
 testFontFamily : TGPFontFamily;
begin
 testgraphics := TGPGraphics.Create(SElf.Handle);
 testPen := TGPPen.Create(aclBlack);
 testFontFamily := TGPFontFamily.Create('Arial');
//  testFont := TGPFont.Create(testFontFamily, 12, FontStyleBold, UnitPixel);
 testFont := TGPFont.Create('Arial', 20);
 testBrush := TGPSolidBrush.Create(aclBlack);

//  testgraphics.DrawString('Hello', 5, testFont, MakeRect(0,0,50,50),testBrush);
//  testgraphics.DrawString('Hello Finally', testFont,  MakePoint(0, 0),  testBrush);
end;
eesther
  • 57
  • 1
  • 7
  • 1
    Well, look the declaration of DrawString and work out what you need to pass – David Heffernan Jan 14 '15 at 12:01
  • 4
    In the first attempt you are missing the `stringFormat` parameter when calling the overload with `layoutRect`. In the second one you mismatched the `length` parameter with `font`. And in both cases you need to produce the floating structure variant, so your constants should contain a floating point values. [`This should compile`](http://pastebin.com/mfL7D3aW). – TLama Jan 14 '15 at 12:07
  • 3
    You will have to use the handle of the Canvas not of the Form, too. `testgraphics := TGPGraphics.Create(Canvas.Handle)` – bummi Jan 14 '15 at 12:56
  • 1
    Code Insight can help you figure this out. Uncomment one of the calls to `testGraphics.DrawString`, place the editor's cursor right after the opening parenthesis (before `'Hello'`), and type Ctrl+Shift+Space. As you arrow right to each parameter, the bold highlight in the tooltip window changes to show you what parameter you're on and what it expects to receive. – Ken White Jan 14 '15 at 20:39

0 Answers0