Hi again!!
I've got another problem. I'm trying to put together 3 TEdit controls inside a TGroupBox control (TGroupBox1 is the name of new class/control).
This is the code and compiles OK!!:
unit GroupBox1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, Lmessages;
type
TGroupBox1 = class(TGroupBox)
private
{ Private declarations }
FLigado1 : TEdit;
FLigado2 : TEdit;
FLigado3 : TEdit;
procedure x3SetColor (FColor : TColor);
function x3GetColor (): TColor;
procedure x3SetFont (FFont : TFont);
function x3GetFont (): TFont;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner : TComponent) ; override;
destructor Destroy; override;
published
{ Published declarations }
property x3Color : TColor read x3GetColor write x3SetColor;
property x3Font : TFont read x3GetFont write x3SetFont;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard',[TGroupBox1]);
end;
procedure TGroupBox1.x3SetColor (FColor : TColor);
begin
Fligado1.Color := FColor;
Fligado2.Color := FColor;
Fligado3.Color := FColor;
end;
function TGroupBox1.x3GetColor : TColor;
begin
x3GetColor := FLigado1.Color;
end;
procedure TGroupBox1.x3SetFont (FFont : TFont);
begin
if FLigado1.Font = FFont then Exit;
FLigado1.Font.Assign (FFont);
FLigado2.Font.Assign (FFont);
FLigado3.Font.Assign (FFont);
Perform(CM_FONTCHANGED, 0, 0);
end;
function TGroupBox1.x3GetFont (): TFont;
begin
x3GetFont.Assign (Fligado1.Font);
end;
constructor TGroupBox1.Create(AOwner : TComponent);
begin (* Parametros iniciales de TGRoupBox*)
inherited Create (AOwner);
BidiMode := bdRightToLeft;
Height := 136;
Width := 176;
ClientHeight := 118;
ClientWidth := 172;
Constraints.MaxHeight:=136;
Constraints.MaxWidth:=176;
Constraints.MinHeight:=136;
Constraints.MinWidth:=176;
FLigado1:= TEdit.Create(Self);
FLigado1.Parent:= Self;
FLigado1.SetSubComponent(true);
FLigado1.Name:= 'X';
FLigado1.ControlStyle := FLigado1.ControlStyle - [csNoDesignSelectable];
FLigado1.Left := 40;
FLigado1.Height := 24;
FLigado1.Top := 5;
FLigado1.Width := 130;
FLigado2:= TEdit.Create(Self);
FLigado2.Parent:= Self; (* Parametros iniciales del SEGUNDO Subcontrol dentro de TGRoupBox*)
FLigado2.SetSubComponent(true);
FLigado2.Name:= 'Y';
FLigado2.ControlStyle := FLigado2.ControlStyle - [csNoDesignSelectable];
FLigado2.Left := 40;
FLigado2.Height := 24;
FLigado2.Top := 44;
FLigado2.Width := 130;
FLigado3:= TEdit.Create(Self);
FLigado3.Parent:= Self; (* Parametros iniciales del TERCER Subcontrol dentro de TGRoupBox*)
FLigado3.SetSubComponent(true);
FLigado3.Name:= 'Z';
FLigado3.ControlStyle := FLigado3.ControlStyle - [csNoDesignSelectable];
FLigado3.Left := 40;
FLigado3.Height := 24;
FLigado3.Top := 83;
FLigado3.Width := 130;
end;
destructor TGroupBox1.Destroy;
begin
inherited Destroy;
end;
end.
I've a created a new property (x3Color) in the object inspector to change Color inside each TEdit control simultaneously and it works properly, but if I do the same, for changing the font in each TEdit, I get "Acess violation" error. If I delete all the code about "fonts" (x3Font property and functions/procedure, the code is OK)
What's wrong with the font source code?
Best Regards!!