2014-04-13 43 views
0

使用:Lazarus 1.2.0; Windows 32位應用程序在自定義組件(Lazarus)中設置TEdit的Text屬性時引發異常

我創建了一個派生自TCustomPanel的自定義組件,幷包含一些TEdit控件。

在運行時,當我嘗試在組件中設置編輯控件的Text屬性時,出現運行時錯誤。

這是錯誤:

Project project1 raised exception class 'External: SIGSEGV'. 

In file '.\include\control.inc' at line 3246: 
GetTextMethod := TMethod(@Self.GetTextBuf); 

我用Google搜索,但沒有找到任何人設定TEDIT的Text屬性的時候,特意報告這個錯誤。

這使我相信在編寫組件時我做錯了什麼。請檢查我的代碼並指出哪些問題以及如何解決問題。 TIA!

代碼如下:

unit uEditPanel; 

{$mode objfpc}{$H+} 

interface 

uses 
    Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls; 

type 

    { TEditPanel } 

    TEditPanel = class(TCustomPanel) 
    Edit0: TCustomEdit; 
    Edit1: TCustomEdit; 
    Edit2: TCustomEdit; 
    Edit3: TCustomEdit; 
    Edit4: TCustomEdit; 

    private 
    { Private declarations } 
    function GetEdit0Text: string; 
    procedure SetEdit0Text(AText: string); 
    function GetEdit1Text: string; 
    procedure SetEdit1Text(AText: string); 
    function GetEdit2Text: string; 
    procedure SetEdit2Text(AText: string); 
    function GetEdit3Text: string; 
    procedure SetEdit3Text(AText: string); 
    function GetEdit4Text: string; 
    procedure SetEdit4Text(AText: string); 
    protected 
    { Protected declarations } 
    public 
    { Public declarations } 
    procedure CreateWnd; override; 
    published 
    { Published declarations } 
    property Edit0Text: string read GetEdit0Text write SetEdit0Text; 
    property Edit1Text: string read GetEdit1Text write SetEdit1Text; 
    property Edit2Text: string read GetEdit2Text write SetEdit2Text; 
    property Edit3Text: string read GetEdit3Text write SetEdit3Text; 
    property Edit4Text: string read GetEdit4Text write SetEdit4Text; 
    end; 

procedure Register; 

implementation 

procedure Register; 
begin 
    RegisterComponents('Standard', [TEditPanel]); 
end; 

{ TEditPanel } 

function TEditPanel.GetEdit0Text: string; 
begin 
    Result := Edit0.Text; 
end; 

procedure TEditPanel.SetEdit0Text(AText: string); 
begin 
    Edit0.Text := AText; 
end; 

function TEditPanel.GetEdit1Text: string; 
begin 
    Result := Edit1.Text; 
end; 

procedure TEditPanel.SetEdit1Text(AText: string); 
begin 
    Edit1.Text := AText; 
end; 

function TEditPanel.GetEdit2Text: string; 
begin 
    Result := Edit2.Text; 
end; 

procedure TEditPanel.SetEdit2Text(AText: string); 
begin 
    Edit2.Text := AText; 
end; 

function TEditPanel.GetEdit3Text: string; 
begin 
    Result := Edit3.Text; 
end; 

procedure TEditPanel.SetEdit3Text(AText: string); 
begin 
    Edit3.Text := AText; 
end; 

function TEditPanel.GetEdit4Text: string; 
begin 
    Result := Edit4.Text; 
end; 

procedure TEditPanel.SetEdit4Text(AText: string); 
begin 
    Edit4.Text := AText; 
end; 

procedure TEditPanel.CreateWnd; 
begin 
    inherited CreateWnd; 

    Caption := EmptyStr; 
    Height := 117; 
    Width := 289; 
    BevelOuter := bvNone; 
    ClientHeight := 117; 
    ClientWidth := 289; 

    Edit0 := TCustomEdit.Create(Self); 
    Edit1 := TCustomEdit.Create(Self); 
    Edit2 := TCustomEdit.Create(Self); 
    Edit3 := TCustomEdit.Create(Self); 
    Edit4 := TCustomEdit.Create(Self); 

    Edit0.Left := 0; 
    Edit0.Height := 21; 
    Edit0.Top := 0; 
    Edit0.Width := 288; 
    //Edit0.BorderStyle := bsNone; 
    Edit0.TabOrder := 0; 

    Edit1.Left := 0; 
    Edit1.Height := 21; 
    Edit1.Top := 24; 
    Edit1.Width := 288; 
    // Edit1.BorderStyle := bsNone; 
    Edit1.TabOrder := 1; 
    Edit1.Font.Color := clGray; 

    Edit2.Left := 0; 
    Edit2.Height := 21; 
    Edit2.Top := 48; 
    Edit2.Width := 288; 
    // Edit2.BorderStyle := bsNone; 
    Edit2.TabOrder := 2; 
    Edit2.Font.Color := clGray; 

    Edit3.Left := 0; 
    Edit3.Height := 21; 
    Edit3.Top := 72; 
    Edit3.Width := 288; 
    //Edit3.BorderStyle := bsNone; 
    Edit3.TabOrder := 3; 
    Edit3.Font.Color := clGray; 

    Edit4.Left := 0; 
    Edit4.Height := 21; 
    Edit4.Top := 96; 
    Edit4.Width := 288; 
    //Edit4.BorderStyle := bsNone; 
    Edit4.TabOrder := 4; 
    Edit4.Font.Color := clGray; 

    Edit0.Parent := Self; 
    Edit1.Parent := Self; 
    Edit2.Parent := Self; 
    Edit3.Parent := Self; 
    Edit4.Parent := Self; 

    Edit0.SetSubComponent(True); 
    Edit1.SetSubComponent(True); 
    Edit2.SetSubComponent(True); 
    Edit3.SetSubComponent(True); 
    Edit4.SetSubComponent(True); 
end; 

end. 

回答

0

解決。用戶JuhaManninen在Lazarus支持上發佈的答案forum

"You have no constructor in your class. Replace CreateWnd with a constructor."

相關問題