為什麼我設定的caption沒有用﹐(100分)

  • 主题发起人 主题发起人 mis11
  • 开始时间 开始时间
M

mis11

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Plzl1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, Buttons;
type
TPlzl1 = class(TPanel)
private
FaCaption:string;
function getaCaption: string;
procedure setaCaption(Value: string);
protected
public
procedure ff;
constructor Create(AOwner: TComponent);override;
published
{ Published declarations }
property aCaption: string read getaCaption write setaCaption;
end;
procedure Register;
implementation

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

function Tplzl1.getaCaption: string;
begin
result := FaCaption
end;

procedure Tplzl1.setaCaption(Value: string);
begin
FaCaption := Value
end;

constructor TPlzl1.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ff;
end;
procedure tplzl1.ff;
var
SB1: TSpeedButton;
begin
SB1 := TSpeedButton.Create(self);
sb1.Height := 30;
sb1.Width := 75;
sb1.Flat := true;
sb1.Parent := self;
sb1.Caption := aCaption;
end;
end.
 
mark the error pls
 
安裝后我在acaption中輸入文字﹐按鈕的caption沒有顯示
 
请用跟踪看看在哪里出错了!
 
procedure Tplzl1.setaCaption(Value: string);
begin
FaCaption := Value;
sb1.Caption := faCaption; //增加這一句就可以了

end;
 
新問題來了﹐
我把這兩條 sb1.Height := 30;
sb1.Width := 75;
改為
sb1.height := height;
sb1.width := width;
這樣改過后﹐在設計時不能雖著改變它的大小
 
慢了一步,你只更改你自己的变量,没有更新控件的caption,
在setcaption里面增加:
caption:=facaption即可!
 

sb1.height := height;
sb1.width := width;
把這兩句放到 TPanel 的 onresize 事件中試一試
 
大家好又有新問題了﹐我在button里加了一個圖片顯示﹐這可顯示但運行后圖片就不見了
謝謝大家的指點﹐如果分不夠以后寫完這個控件我就加400分給大家.
unit Plzl1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, Buttons;
type
TPlzl1 = class(TPanel)
SB1: TSpeedButton;
private
FaGlyph:TBitmap;
FaOnClick: TNotifyEvent;
FaCaption:string;
function getaCaption: string;
procedure setaCaption(Value: string);
function getaOnClick: TNotifyEvent;
procedure setaOnClick(Value: TNotifyEvent);
function getaglyph: tbitmap;
procedure setaglyph(value :tbitmap);
protected
public
procedure ff;
constructor Create(AOwner: TComponent);override;
procedure Paint; override;
destructor Destroy; override;
published
property aCaption: string read getaCaption write setaCaption;
property OnaClick: TNotifyEvent read getaOnClick write setaOnClick;
property aGlyph: TBitmap read GetaGlyph write SetaGlyph;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TPlzl1]);
end;
procedure tplzl1.Paint;
begin
inherited;
sb1.caption := facaption;
sb1.Width := width;
sb1.Height := height;
end;
function Tplzl1.getaCaption: string;
begin
result := FaCaption;
end;
procedure Tplzl1.setaCaption(Value: string);
begin
FaCaption := Value;
end;
constructor TPlzl1.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
self.Caption := '';
ff;
end;
procedure Tplzl1.setaOnClick(Value: TNotifyEvent);
begin
FaOnClick := Value;
sb1.OnClick := Value;
end;

function Tplzl1.getaOnClick: TNotifyEvent;
begin
result := FaOnClick
end;
function tplzl1.getaglyph:tbitmap;
begin
result := Faglyph;
end;
procedure tplzl1.setaglyph(value :tbitmap);
begin
// faglyph:=value;
sb1.Glyph := value;
end;
procedure tplzl1.ff;
begin
SB1 := TSpeedButton.Create(self);
sb1.Height := height;
sb1.Width := width;
sb1.Flat := true;
sb1.Parent := self;
sb1.Caption := aCaption;
end;
destructor Tplzl1.Destroy;
begin
sb1.Free;
inherited Destroy;
end;

end.
 
可以出来啊,你再试试,
不过你只是测试CAPTION的话,procedure ff;根本就没有用的
 
unit Plzl1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls,Buttons;
type
TPlzl1 = class(TPanel)
SB1: TSpeedButton;
private

FaOnClick: TNotifyEvent;
FaCaption:string;
function getaCaption: string;
procedure setaCaption(Value: string);
function getaOnClick: TNotifyEvent;
procedure setaOnClick(Value: TNotifyEvent);
procedure setaglyph(value :tbitmap);
function getaglyph:tbitmap;

protected
public
procedure ff;
constructor Create(AOwner: TComponent);override;
destructor Destroy; override;
published
property aCaption: string read getaCaption write setaCaption;
property OnaClick: TNotifyEvent read getaOnClick write setaOnClick;
property aGlyph: TBitmap read getaGlyph write SetaGlyph;
end;
procedure Register;
implementation

procedure Register;
begin
RegisterComponents('Standard', [TPlzl1]);
end;
function Tplzl1.getaCaption: string;
begin
result := FaCaption;
end;
procedure Tplzl1.setaCaption(Value: string);
begin
FaCaption := Value;
sb1.caption := facaption;
end;
constructor TPlzl1.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
self.Caption := '';
ff;
end;
procedure Tplzl1.setaOnClick(Value: TNotifyEvent);
begin
FaOnClick := Value;
sb1.OnClick := Value;
end;

function Tplzl1.getaOnClick: TNotifyEvent;
begin
result := FaOnClick
end;
function Tplzl1.getaglyph:tbitmap;
begin
result:=sb1.Glyph;
end;

procedure tplzl1.setaglyph(value :tbitmap);
begin
// faglyph:=value;
sb1.Glyph := Value;
end;
procedure tplzl1.ff;
begin
SB1 := TSpeedButton.Create(self);
sb1.Align:=alClient; //這一句就可一實現你下面倆句的功能
// sb1.Height := height;
// sb1.Width := width;
sb1.Flat := true;
sb1.Parent := self;
sb1.Caption := aCaption;
end;
destructor Tplzl1.Destroy;
begin
sb1.Free;
inherited Destroy;
end;

end.
 
后退
顶部