OK, I removed all jvuib items and now the code looks litke this (it still doesn't work):
ubobject.pas:
---------------
unit ubobject;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Dialogs;
type
TBObject = class(TPersistent)
private
FId: longint;
RelTable: string;
procedure FetchData(); //çàãíàòü äàííûå èç ÁÄ â ñâîéñòâà
//ïîäãîòîâêà ê ôóíêöèÿì Find...
procedure PrepareQueryForFinding(const Field: string);
function ExecuteFinding(): boolean; //çàâåðøåíèå ôóíêöèé Find...
protected
public
Fields: TStringList; //ñïèñîê ñîîòíîøåíèé ÑÂÎÉÑÒÂÎ=ÏÎËÅ
constructor Create(); virtual;
destructor Destroy(); override;
procedure New(); virtual; //íîâûé ýëåìåíò
procedure ShowElement(); //îòêðûòü ôîðìó ýëåìåíòà
function SelectAll(): boolean; virtual; //âûáðàòü âñå ýëåìåíòû
//ïîëó÷èòü ñëåäóþùèé ýëåìåíò ïîñëå âûáîðêè
function GetNext(): boolean; virtual;
//íàéòè ýëåìåíò ïî ïîëþ è çíà÷åíèþ
function FindByField(const Field, Value: string): boolean;
function FindByField(const Field: string; const Value: longint): boolean;
function FindByID(const TheID: longint): boolean;
function Find(ABObject: TBObject): boolean;
function Save(): boolean; virtual; //ñîõðàíèòü îáúåêò
function IsNew(): boolean; //true - åñëè íîâûé ýëåìåíò
published
property ID: longint read FId write FId;
end;
TBObjects = class of TBObject;
var
BObject: TBObject;
implementation
uses Main, Inifiles, TypInfo, basic;
constructor TBObject.Create();
var
i, count: integer;
cbobject: TBObjects;
fieldname: string;
begin
inherited Create;
RelTable:=Copy(ClassName, 2, Length(ClassName)-1);
Fields:=TStringList.Create();
with TInifile.Create(ExtractFilePath(ParamStr(0))+'Main.ini') do begin
ReadSectionRaw(self.ClassName, Fields);
Free;
end;
count:=Fields.Count-1;
for i:=0 to count do begin
fieldname:=Fields.Names;
if PropType(self,FieldName)=tkClass then
if GetObjectPropClass(Self, FieldName).InheritsFrom(TBObject) then begin
cbobject:=TBObjects(GetObjectPropClass(self, FieldName));
SetObjectProp(self, FieldName, cbObject.Create());
end;
end;
end;
destructor TBObject.Destroy();
var
i, count: integer;
fieldname: string;
begin
count:=Fields.Count-1;
for i:=0 to count do begin
fieldname:=Fields.Names;
if PropType(self,FieldName)=tkClass then
if GetObjectPropClass(Self, FieldName).InheritsFrom(TBObject) then begin
GetObjectProp(self, FieldName).Free;
end;
end;
if Fields<> nil then Fields.Free;
inherited;
end;
procedure TBObject.New();
var
i, count: integer;
FieldName: string;
TypeKind: TTypeKind;
begin
count:=Fields.Count-1;
for i:=0 to count do begin
FieldName:=Fields.Names;
TypeKind:=PropType(self, FieldName);
case TypeKind of
tkInteger, tkInt64, tkQWord:
SetInt64Prop(self, FieldName, 0);
tkSString, tkLString, tkAString, tkWString:
SetStrProp(self, FieldName,'sss');
else
Raise Exception.Create('Íåçíàêîìûé òèï äëÿ TBObject!');
end;
end;
end;
function TBObject.SelectAll(): boolean;
begin
result:=true;
end;
function TBObject.GetNext(): boolean;
begin
result:=true;
end;
procedure TBObject.FetchData();
begin
end;
procedure TBObject.PrepareQueryForFinding(const Field: string);
begin
end;
function TBObject.ExecuteFinding(): boolean;
begin
result:=true;
end;
function TBObject.FindByField(const Field, Value: string): boolean;
begin
result:=true;
end;
function TBObject.FindByField(const Field: string; const Value: longint): boolean;
begin
result:=true;
end;
function TBObject.FindByID(const TheID: longint): boolean;
begin
result:=true;
end;
function TBObject.Find(ABObject: TBObject): boolean;
begin
result:=true;
end;
procedure TBObject.ShowElement();
begin
end;
function TBObject.Save(): boolean;
begin
showmessage('RelTable='+RelTable);
result:=false;
end;
function TBObject.IsNew(): boolean;
begin
result:=FId=0;
end;
initialization
{$I ubobject.lrs}
end.
===================================
umetadata.pas:
----------------
unit umetadata;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, ubobject;
type
TResidence = class(TBObject)
private
FName: string;
published
property Name: string read FName write FName;
end;
TEmployee = class(TBObject)
private
FName: string;
FResidence: TResidence;
published
property Name: string read FName write FName;
property Residence: TResidence read FResidence write FResidence;
end;
implementation
end.
======================================
Main.pas:
-----------
unit Main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
Buttons;
type
TfmMain = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure fmMainShow(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
fmMain: TfmMain;
implementation
uses umetadata;
{ TfmMain }
procedure TfmMain.fmMainShow(Sender: TObject);
begin
Top:=0;
Left:=0;
Width:=Screen.Width;
end;
procedure TfmMain.Button1Click(Sender: TObject);
var bob: TEmployee;
begin
bob:=TEmployee.Create();
bob.New();
bob.Name:='Nothingx like the rain';
ShowMessage(BoolToStr(bob.Save()));
bob.Free();
end;
initialization
{$I main.lrs}
end.
=========================================
Main.ini:
-----------
[TRESIDENCE]
Name=NAME
[TEMPLOYEE]
Id=ID_REF
Name=NAME