Forum > Packages and Libraries
Edit object inspector (SOLVED)
JuhaManninen:
--- Quote from: xinyiman on June 20, 2011, 05:01:36 pm ---I want to see in the graphic of the new entries in the IDE Object Inspector.
--- End quote ---
What graphic you mean?
Juha
xinyiman:
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?
xinyiman:
Solved with this code
--- 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.
--- End code ---
Navigation
[0] Message Index
[*] Previous page