Jump to content

Recommended Posts

Posted

Hi,

 

I try to learn fast how create unigui web component , so I have get from samples -control1- and I try to add property like changing color button.

The component that I have modified can not change color, I don't know why

I have try to attach the modified code but there is error when uploading file (Error You aren't permitted to upload this kind of file)

Can you help me please.

This is the code below :

//-------------------------------------------------------------------------------------------------------------------
unit UniCustomControl1;
interface
uses
  SysUtils, Classes, Controls, uniGUIBaseClasses, uniGUIClasses,
  extctrls,Graphics;
type
  // TUniControl is base for all visual controls
  // TuniControl is not a container and can not be a parent for other TUniControls
  TUniMyButton = class(TUniControl)
  private
    { Private declarations }
    FHrefTarget : string;
    FHref : string;
    FPressed : Boolean;
    fLedColor : TColor;
    fIsLedOn : boolean;
  protected
    function GetLedColor : TColor;
    procedure SetLedColor (LedColor : TColor);
    procedure ConfigJSClasses(ALoading: Boolean); override;
    function VCLControlClassName: string; override;
    function GetHref: string;
    procedure SetHref(const Value: string);
    procedure InternalSetCaption(Value: string); override;
    function GetHrefTarget: string;
    procedure SetHrefTarget(const Value: string);
    procedure WebCreate; override;
    procedure LoadCompleted; override;
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Href: string read GetHref write SetHref;
    property HrefTarget: string read GetHrefTarget write SetHrefTarget;
    property Pressed: Boolean read FPressed write FPressed default False;
    property LedColor : TColor read GetLedColor write SetLedColor;
    property Caption;
    property RTL;
  end;
procedure Register;
implementation
procedure TUniMyButton.SetLedColor (LedColor : TColor);
begin
  if FLedColor<>LedColor then
  begin
    FLedColor:=LedColor;
    JSProperty('LedColor', [fLedColor], 'SetLedColor');
  end;
end;
function TUniMyButton.GetLedColor : TColor;
begin
     Result := fLedColor;
end;
procedure TUniMyButton.ConfigJSClasses(ALoading: Boolean);
begin
  JSObjects.DefaultJSClassName:='Ext.button.Button';
end;
function TUniMyButton.VCLControlClassName: string;
begin
  Result:='';
end;
constructor TUniMyButton.Create(AOwner: TComponent);
begin
  inherited;
  Width:=85;
  Height:=25;
  FHrefTarget := '_blank';
end;
procedure TUniMyButton.WebCreate;
begin
  inherited;
  JSConfig('border', [5]);
  JSConfig('LedColor',  [GetLedColor]);
end;
procedure TUniMyButton.LoadCompleted;
begin
  inherited;
  JSConfig('pressed', [FPressed]);
end;
function TUniMyButton.GetHref: string;
begin
  Result:=FHref;
end;
procedure TUniMyButton.SetHref(const Value: string);
begin
  if FHref<>Value then
  begin
    FHref:=Value;
    JSProperty('href', [FHref], 'setHref');
  end;
end;
function TUniMyButton.GetHrefTarget: string;
begin
  Result:=FHrefTarget;
end;
procedure TUniMyButton.SetHrefTarget(const Value: string);
begin
  if FHrefTarget<>Value then
  begin
    FHrefTarget:=Value;
    JSProperty('hrefTarget', [FHrefTarget]);
  end;
end;
procedure TUniMyButton.InternalSetCaption(Value: string);
begin
  inherited;
  JSProperty('text', [Value], 'setText');
end;
procedure Register;
begin
  RegisterComponents('uniSamples', [TUniMyButton]);
end;
end.
//-------------------------------------------------------------------------------------------------------------------

Thank you

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...