Lazarus
Programming => Packages and Libraries => Topic started by: xinyiman 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 (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
-
Your component source has 4 sections: Private, Protected, Public and Published. Properties and Events from Published section will appear in OI.
-
Thank you
-
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.
-
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 (http://wiki.lazarus.freepascal.org/images/2/25/ObjectInspector-TForm.png)
-
I want to see in the graphic of the new entries in the IDE Object Inspector.
What graphic you mean?
Juha
-
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?
-
Solved with this code
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.