2013-01-25 178 views
0

我已經創建了一個新的單位,它應該是一個自定義的TShape。在自定義TShape上設置寬度/高度

unit MachineShape; 


interface 

uses 
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, 
    Vcl.Controls, extctrls,myDataModule,Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; 

type 

TMachine = class(TShape) 
    count : Integer; 
    private 
    { Private declarations } 
    public 
    { Public declarations } 
    procedure PlaceShape(sizeW,sizeH :integer; name, order,asset : string); 
    end; 
implementation 

    Procedure PlaceShape(sizeW,sizeH :integer; name, order,asset : string); 
    begin 

    end; 

end. 

下一I它傳遞給過程

MachineShape.TMachine.PlaceShape(44,49,'CM402','first','123/33/123'); 

我如何在程序設置爲設定的形狀尺寸爲44的寬度和高度49?

我試過做TMachine.Width但它不起作用? 感謝 格倫

回答

2

您已經聲明PlaceShape是一個實例方法,因此需要實現它是這樣:

Procedure TMachine.PlaceShape(sizeW,sizeH :integer; name, order,asset : string); 
begin 
    Width := sizeW; 
    Height := sizeH; 
    .... 
end; 

你聲明的函數

Procedure PlaceShape(...); 

這不是一個方法的類。

此問題表明您錯過了對Delphi模型的一些理解。我會把你推薦到relevant section of the language guide來填補遺漏的知識。

我還建議您爲尺寸參數使用不同的名稱。您應該使用AWidthAHeight,以便未來的代碼讀者清楚這些參數將用於設置相應的形狀屬性。

+0

我現在明白了,出於某種原因,當我做了TMachine。 PlaceShape不會出現一個編譯/構建固定它..謝謝! –

相關問題