Recent

Author Topic: Edit object inspector (SOLVED)  (Read 8968 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Edit object inspector (SOLVED)
« on: June 20, 2011, 11:48:41 am »
Hello, I would create a new package and I already know how to do, just follow this guide: http://wiki.lazarus.freepascal.org/How_To_Write_Lazarus_Component


what you do not understand is how to change the object inspector, so as to make my new components easier to use.

Can anyone tell me how?

Thank you
« Last Edit: June 21, 2011, 11:38:30 am by xinyiman »
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Edit object inspector
« Reply #1 on: June 20, 2011, 01:21:05 pm »
Your component source has 4 sections: Private, Protected, Public and Published. Properties and Events from Published section will appear in OI.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Edit object inspector
« Reply #2 on: June 20, 2011, 01:23:25 pm »
Thank you
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Edit object inspector
« Reply #3 on: June 20, 2011, 05:01:36 pm »
I guess I did not explain, I want to see in the graphic of the new entries in the IDE Object Inspector. And I do not understand how. Simply doing what you tell me I can not do it.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Edit object inspector
« Reply #4 on: June 21, 2011, 07:48:09 am »
No one who knows tell me how can I put new entries in the Object Inspector?

http://wiki.lazarus.freepascal.org/images/2/25/ObjectInspector-TForm.png
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Edit object inspector
« Reply #5 on: June 21, 2011, 08:36:56 am »
I want to see in the graphic of the new entries in the IDE Object Inspector.

What graphic you mean?

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Edit object inspector
« Reply #6 on: June 21, 2011, 10:40:04 am »
I mean visually, not through the source code I want to set the parameters of my new object. How do I extend the new object in the Object Inspector?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Edit object inspector
« Reply #7 on: June 21, 2011, 11:38:14 am »
Solved with this code

Code: [Select]
unit ExtDBListBox;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Grids, sqldb, db;

type
  TExtDBListBox = class(TStringGrid)
  private
    { Private declarations }
    MyDataSource: TDataSource;     //Self.MyDataSource.OnDataChange
    Intestazione: boolean;
  protected
    { Protected declarations }
    procedure SetDataSource(AppDataSource: TDataSource);
  public
    { Public declarations }
    constructor Create(TheOwner: TComponent); override;
    procedure Requery();
    procedure ColumnVisible(ColIndex: integer; Value: boolean);
    procedure ColumnAlign(ColIndex: integer; Value: integer);
  published
    { Published declarations }
    property AppDataSource: TDataSource read MyDataSource write MyDataSource;
  end;

procedure Register;

implementation

procedure Register;
begin
  {$I ExtDBListBox_icon.lrs}
  RegisterComponents('Standard',[TExtDBListBox]);
end;

constructor TExtDBListBox.Create(TheOwner: TComponent);
begin
     inherited Create(TheOwner);
     {cambio il layout della griglia per far si che si veda come se fosse una listbox}
     Self.ColCount:=1;
     Self.FixedCols:=0;
     Self.FixedRows:=0;
     Self.AutoEdit:=false;
     Self.GridLineWidth:=0;
     Intestazione:=FALSE;
end;

procedure TExtDBListBox.Requery();
var
   NumRighe, NumColonne: LongInt;
   Colonna, Riga: integer;
   app:string;
begin

     Self.SetDataSource(AppDataSource);

     Self.Clear; //pulisco la listbox
     {ora disegno il dataset}
     if not MyDataSource.DataSet.EOF then
     begin
          {mi ricavo il numero di colonne che devo stampare a video}
          NumColonne:=MyDataSource.DataSet.FieldCount;
          Self.ColCount:=NumColonne;
          {mi scorro velocemente il recordset per capire quante righe ho}
          MyDataSource.DataSet.First;
          NumRighe:=0;
          while not MyDataSource.DataSet.EOF do
          begin
               Inc(NumRighe);
               MyDataSource.DataSet.Next;
          end;
          {ora che ho il numero di righe mi stampo la griglia}
          if Intestazione=TRUE then
          begin
               Self.RowCount:=NumRighe+1;
               {ora inserisco la testata}
               for Colonna:=0 to NumColonne-1 do
               begin
                    app:=MyDataSource.DataSet.Fields[Colonna].Name;
                    if Length(Trim(app))<=0 then
                       app:='Col' + IntToStr(Colonna);
                    Self.Cells[Colonna,0]:=app;
               end;
               Riga:=1;
          end
          else
          begin
               //Self.Columns.Add.Create(nil);
               Self.RowCount:=NumRighe;
               Riga:=0;
          end;
          {ora inserisco i dati}
          MyDataSource.DataSet.First;
          while not MyDataSource.DataSet.EOF do
          begin
               {disegno la singola riga}
               for Colonna:=0 to NumColonne-1 do
               begin
                    Self.Cells[Colonna,Riga]:=MyDataSource.DataSet.Fields[Colonna].AsString;
               end;
               Inc(Riga);
               MyDataSource.DataSet.Next;
          end;
     end;
     Self.AutoSizeColumns; //dimensiona le colonne correttamente
end;

procedure TExtDBListBox.ColumnVisible(ColIndex: integer; Value: boolean);
begin
     Self.Columns[ColIndex].Visible:=Value;
end;

procedure TExtDBListBox.ColumnAlign(ColIndex: integer; Value: integer);
begin
     if Value<0 then
        Self.Columns[ColIndex].Alignment:=taLeftJustify
     else if Value=0 then
          Self.Columns[ColIndex].Alignment:=taCenter
     else
         Self.Columns[ColIndex].Alignment:=taRightJustify;
end;

procedure TExtDBListBox.SetDataSource(AppDataSource: TDataSource);
begin
     Self.MyDataSource:=AppDataSource;
end;

{procedure TExtDBListBoxPrepareCanvas(sender: TObject; aCol, aRow: Integer; aState: TGridDrawState);
var
  MyTextStyle: TTextStyle;
begin
  if (aCol=2) or (aCol=3) then
  begin
    MyTextStyle := StringGrid1.Canvas.TextStyle;
    if aCol=2 then
      MyTextStyle.Alignment := taRightJustify
    else
    if aCol=3 then
      MyTextStyle.Alignment := taCenter;
    StringGrid1.Canvas.TextStyle := MyTextStyle;
  end;
end;}

end.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

 

TinyPortal © 2005-2018