با عرض سلام
من روی این کومپوننت کار کردم و تا یه جاهای پیش رفتم.
یه نگاه بندازید.
unit MyControls;
interface
uses
SysUtils,Classes,ExtCtrls,Controls,StdCtrls;
type
TMyBoundEdit = class (TEdit)
private
{ Private-Deklarationen }
function GetLeft :Integer;
function GetTop :Integer;
procedure SetLeft(const Value: Integer);
procedure SetTop(const Value: Integer);
procedure SetHeight(const Value: Integer);
procedure SetWidth(const Value: Integer);
// procedure OnExit(Sender: TObject);
protected
{ Protected-Deklarationen }
public
constructor Create(AOwner: TComponent); override;
{ Public-Deklarationen }
published
property Top: Integer read GetTop write SetTop;
property Left: Integer read GetLeft write SetLeft;
{ Published-Deklarationen }
end;
TMyBoundLabel = class (TLabel)
private
{ Private-Deklarationen }
function GetLeft :Integer;
function GetTop :Integer;
procedure SetLeft(const Value: Integer);
procedure SetTop(const Value: Integer);
protected
{ Protected-Deklarationen }
public
{ Public-Deklarationen }
constructor Create(AOwner: TComponent); override;
published
property Top: Integer read GetTop write SetTop;
property Left: Integer read GetLeft write SetLeft;
{ Published-Deklarationen }
end;
TMyBoundEditLabel = class (TLabel)
private
{ Private-Deklarationen }
function GetLeft :Integer;
function GetTop :Integer;
procedure SetLeft(const Value: Integer);
procedure SetTop(const Value: Integer);
protected
{ Protected-Deklarationen }
public
{ Public-Deklarationen }
constructor Create(AOwner: TComponent); override;
published
property Top: Integer read GetTop write SetTop;
property Left: Integer read GetLeft write SetLeft;
{ Published-Deklarationen }
end;
TMyLabelEdit = class (TWinControl)
private
{ Private-Deklarationen }
FMyEdit:TMyBoundEdit;
FMyLabel:TMyBoundLabel;
FMyEditText:TMyBoundEditLabel;
protected
{ Protected-Deklarationen }
procedure SetParent(AParent: TWinControl); override;
// procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure SetName(const Value: TComponentName); override;
public
{ Public-Deklarationen }
constructor Create(AOwner: TComponent); override;
// destructor Destroy(AOwner: TComponent); override;
published
property fEdit: TMyBoundEdit read FMyEdit ;
property fLabel: TMyBoundLabel read FMyLabel ;
property fEditText: TMyBoundEditLabel read FMyEditText ;
{ Published-Deklarationen }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Farid Controls', [TMyLabelEdit]);
end;
constructor TMyBoundEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Name := 'SubEdit'; { do not localize }
SetSubComponent(True);
if Assigned(AOwner) then
Text := AOwner.Name;
end;
procedure TMyBoundEdit.SetHeight(const Value: Integer);
begin
inherited height:= Value;
end;
procedure TMyBoundEdit.SetWidth(const Value: Integer);
begin
inherited width:= Value;
end;
procedure TMyBoundEdit.SetTop(const Value: Integer);
begin
inherited top:= Value ;
end;
procedure TMyBoundEdit.SetLeft(const Value: Integer);
begin
inherited left:=Value;
end;
function TMyBoundEdit.GetTop :Integer;
begin
Result := inherited Top ;
end;
function TMyBoundEdit.GetLeft :Integer;
begin
Result := inherited Left;
end;
{procedure TMyBoundEdit.OnExit(Sender: TObject);
begin
//FMyEdit.Caption := MyLabelEdit1.fEdit.Text;
// Visible := false;
end;}
constructor TMyBoundEditLabel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Name := 'EditText'; { do not localize }
SetSubComponent(True);
if Assigned(AOwner) then
Caption := AOwner.Name;
end;
function TMyBoundEditLabel.GetTop :Integer;
begin
Result := inherited Top;
end;
function TMyBoundEditLabel.GetLeft :Integer;
begin
Result := inherited Left;
end;
procedure TMyBoundEditLabel.SetTop(const Value: Integer);
begin
inherited top:= Value ;
end;
procedure TMyBoundEditLabel.SetLeft(const Value: Integer);
begin
inherited left:=Value;
end;
constructor TMyBoundLabel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
try
Name := 'SubLabel'; { do not localize }
except
Name := 'SubLabel2';
end;
SetSubComponent(True);
if Assigned(AOwner) then
Caption := AOwner.Name;
end;
function TMyBoundLabel.GetTop :Integer;
begin
Result := inherited Top;
end;
function TMyBoundLabel.GetLeft :Integer;
begin
Result := inherited Left;
end;
procedure TMyBoundLabel.SetTop(const Value: Integer);
begin
inherited top:= Value ;
end;
procedure TMyBoundLabel.SetLeft(const Value: Integer);
begin
inherited left:=Value;
end;
constructor TMyLabelEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
if Assigned(FMyLabel) then exit;
FMyLabel := TMyBoundLabel.Create(Self);
//Width := 125;
FMyLabel.FreeNotification(Self);
if Assigned(FMyEditText) then exit;
FMyEditText := TMyBoundEditLabel.Create(Self);
FMyEditText.top := 15;
FMyEditText.font.Size := 14;
// FMyEditText.Font.Style := [TFontStyle.fsBold]
FMyEditText.Anchors := [akLeft,akBottom,akRight];
FMyEditText.FreeNotification(Self);
if Assigned(FMyEdit) then exit;
FMyEdit := TMyBoundEdit.Create(Self);
FMyEdit.Top := 15;
FMyEdit.Visible := False;
FMyEdit.font.Size := 14;
//FMyEdit.Font.Style := [fsBold];
FMyEdit.Anchors := [akLeft,akBottom,akRight];
FMyEdit.FreeNotification(Self);
end;
{procedure TMyLabelEdit.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (AComponent = FMyLabel) and (Operation = opRemove) then
FMyLabel := nil;
end; }
procedure TMyLabelEdit.SetName(const Value: TComponentName);
begin
if (csDesigning in ComponentState) and ((FMyLabel.GetTextLen = 0) or
(CompareText(FMyLabel.Caption, Name) = 0)) then
begin
FMyLabel.Caption := Value;
FMyEdit.Text := Value;
FMyEditText.Caption := Value;
end;
inherited SetName(Value);
end;
procedure TMyLabelEdit.SetParent(AParent: TWinControl);
begin
inherited SetParent(AParent);
if FMyEdit = nil then exit;
FMyEdit.Parent := self; // AParent;
FMyEdit.Visible := True;
if FMyLabel = nil then exit;
FMyLabel.Parent := self; // AParent;
FMyLabel.Visible := True;
if FMyEditText = nil then exit;
FMyEditText.Parent := self; // AParent;
FMyEditText.Visible := True;
end;
initialization
finalization
end.
==================
procedure TForm1.OnExit1(Sender: TObject);
begin
(sender as TMyBoundEdit).Visible := False;
(((sender as TMyBoundEdit).Parent) as TMyLabelEdit).fEditText.Caption :=
(sender as TMyBoundEdit).text;
end;
procedure TForm1.OnDblClick1(Sender: TObject);
begin
(((sender as TMyBoundEditLabel).Parent) as TMyLabelEdit).fEdit.Visible := True;
end;
========================
الان اگه بخوام دو بخش بعد از End. رو در رویداد OnDblClick EditText و OnExit Edit اضافه کنم باید چطور بنویسم؟