Forum > Packages and Libraries
My package error
(1/1)
xinyiman:
Why this error in my package code
Error creating component: TExtDBListBox Access violation
--- 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;
protected
{ Protected declarations }
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 }
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;
Self.Requery(); //disegno la griglia
end;
procedure TExtDBListBox.Requery();
var
NumRighe: LongInt;
Colonna, Riga: integer;
begin
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}
Self.Col:=MyDataSource.DataSet.FieldCount;
{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}
Self.Row:=NumRighe+1;
{ora inserisco la testata}
for Colonna:=0 to Self.Col-1 do
begin
Self.Cells[Colonna,0]:=MyDataSource.DataSet.Fields[Colonna].Name;
end;
{ora inserisco i dati}
Riga:=1;
MyDataSource.DataSet.First;
while not MyDataSource.DataSet.EOF do
begin
{disegno la singola riga}
for Colonna:=0 to Self.Col-1 do
begin
Self.Cells[Colonna,Riga]:=MyDataSource.DataSet.Fields[Colonna].AsString;
end;
Inc(Riga);
MyDataSource.DataSet.Next;
end;
end;
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;
end.
--- End code ---
xinyiman:
This error happens when I insert the new component on a form. The compilation did not give errors. Why I'm missing some information?
xinyiman:
I resolved, I was missing the dependency to LCL.
Navigation
[0] Message Index