CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

Using percentage for size and position

by fateh78 » 07 Apr 2017 19:02

Why not supporting percentage for size and position for your components !!??
i think it is not difficult (just adding new property for unit px/%)

best regards
fateh78
 
Posts: 85
Joined: 16 Mar 2017 21:45

by Alexander Bulei » 10 Apr 2017 09:15

Hi fateh78,

Why not supporting percentage for size and position for your components !!??
i think it is not difficult (just adding new property for unit px/%)


We don't control that....you should ask atozed about it :)

Best Regards.
Group: Developers | Support Team

  • info [at] cgdevtools.com - General information
  • sales [at] cgdevtools.com - Sales department
  • support [at] cgdevtools.com - Product and Technical Support
User avatar
Alexander Bulei
Site Admin
 
Posts: 3635
Joined: 15 May 2012 08:52
Location: Mealhada, Portugal

by fateh78 » 10 Apr 2017 11:30

i have already asked
https://forums.embarcadero.com/message.jspa?messageID=883218

any way i also spent 5 days (faced many problems) to do this for my own purposes and it is working fine :
code example for combobox component :

Code: Select all
unit MWDBComboBox;

interface

uses
  //IWCGLicenseKey,
  Windows, SysUtils, Classes, IWBaseControl, IWCGDsnPaint, gFarahFuncs,
  //IWDsnPaint, IWCGDsnPaint, IWCGDsnPaintHandlers,
  IWCGJQControl, IWCGJQCommon, IWRenderContext, IWBaseHTMLControl, UITypes,
  IWHTMLTag, IWXMLTag, IWBaseRenderContext, IWApplication, IWCGJSSuperObject,

  Marah_Funcs, DB, IWCGJQComboBox;

type
  TMWDBComboBox = class(TIWCGJQComboBoxEx)
  private
    { Private declarations }
    fAccessType : TAccessType;
    fVisibility : Boolean;
    FEnability : Boolean;
    fLookupDataSet : TDataSet;
    fLookupKeyField: string;
    fLookupListField : string;
    fContainerStyle: TIWCGStyle;
    function  GetContainerStyle: TIWCGStyle;
    procedure SetContainerStyle(const Value: TIWCGStyle);

    procedure SetAccessType(Value : TAccessType);
    procedure SetVisibility(Value: Boolean);
    procedure SetEnability(Value: Boolean); virtual;
    procedure SetLookupDataSet(Value: TDataSet);
  protected
    { Protected declarations }
    function RenderAsync(AContext: TIWCompContext): TIWXMLTag; override;
    function RenderStyle(AComponentContext: TIWCompContext): string; override;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor  Destroy; override;
    function    RenderHTML(AContext: TIWCompContext): TIWHTMLTag; override;

    procedure   FillItemsFromLookupDS;
  published
    { Published declarations }
    Property AccessType : TAccessType read fAccessType write SetAccessType Default atEdit;
    property Visibility : Boolean read fVisibility write SetVisibility default True;
    property Enability : Boolean read fEnability write SetEnability default True;
    property LookupDataSet : TDataSet read fLookupDataSet write SetLookupDataSet;
    property LookupKeyField : string read fLookupKeyField write fLookupKeyField;
    property LookupListField : string read fLookupListField write fLookupListField;
    property ContainerStyle: TIWCGStyle read GetContainerStyle write SetContainerStyle;
  end;

procedure Register;

implementation


constructor TMWDBComboBox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  fAccessType := atEdit;
  fVisibility := True;
  fEnability := True;

  //FillItemsFromLookupDS;
end;

destructor TMWDBComboBox.Destroy;
begin
  FreeAndNil(FContainerStyle);

  inherited;
end;

function TMWDBComboBox.GetContainerStyle: TIWCGStyle;
begin
  if not Assigned(FContainerStyle) then
     FContainerStyle:= TIWCGStyle.Create;
  Result:= FContainerStyle;
end;

procedure TMWDBComboBox.SetContainerStyle(const Value: TIWCGStyle);
begin
  ContainerStyle.Assign(Value);
end;

function TMWDBComboBox.RenderStyle(AComponentContext: TIWCompContext): string;
var
  SL: TIWCGStyle;
begin
  Result:= inherited RenderStyle(AComponentContext);
  SL:= TIWCGStyle.Create;
  try
    SL.IWStyle:= Result + CGInsertSemiColon(ContainerStyle.RawStyle);
    Result:= SL.RawStyle;
  finally
    SL.Free;
  end;
end;


function TMWDBComboBox.RenderAsync(AContext: TIWCompContext): TIWXMLTag;
begin
  Result:= inherited RenderAsync(AContext);
end;

function TMWDBComboBox.RenderHTML(AContext: TIWCompContext): TIWHTMLTag;
begin
  FillItemsFromLookupDS;

  Result:= inherited RenderHTML(AContext);
end;

procedure TMWDBComboBox.FillItemsFromLookupDS;
begin
  FillComboBoxFromItemsFromDS(Self);
end;

procedure TMWDBComboBox.SetAccessType(Value : TAccessType);
begin
  if fAccessType <> Value then begin
     fAccessType := Value;
     Visible := fVisibility And (fAccessType <> atNone);
     Enabled := fEnability And (fAccessType = atEdit);
  end;
end;

procedure TMWDBComboBox.SetVisibility(Value: Boolean);
begin
  if fVisibility <> Value then begin
     fVisibility := Value;
     Visible := fVisibility And (fAccessType <> atNone);
  end;
end;

procedure TMWDBComboBox.SetEnability(Value: Boolean);
begin
  if fEnability <> Value then begin
     fEnability := Value;
     Enabled := fEnability And (fAccessType = atEdit);
  end;
end;

procedure TMWDBComboBox.SetLookupDataSet(Value: TDataSet);
begin
  if fLookupDataSet <> Value then begin
     fLookupDataSet := Value;

     FillItemsFromLookupDS;
  end;
end;

procedure Register;
begin
  RegisterComponents('Marah Almosa', [TMWDBComboBox]);
  IWRegisterPaintHandler('TMWDBComboBox',TIWCGJQPaintHandlerDsn);
end;

end.



just focus on new property : property ContainerStyle: TIWCGStyle read GetContainerStyle write SetContainerStyle;
later at my form oncreate event i add style to this property like this :

if (TempComp is TMWComboBox) then begin
if (TempComp as TMWDBLookupComboBox).Caption = '' then (TempComp as TMWDBLookupComboBox).Caption := ' ';
(TempComp as TMWComboBox).ContainerStyle.Add('width: ' + WidthRatioStr + '%');
(TempComp as TMWComboBox).ContainerStyle.Add('left: ' + LefttRatioStr + '%');
end
fateh78
 
Posts: 85
Joined: 16 Mar 2017 21:45


Return to General

cron

Who is online

Users browsing this forum: No registered users and 3 guests

Contact Us.