You are not logged in.
Pages: 1
I want to create a class TSQLBaseReport and then derive it into two class TSQLPDFReport and TSQLXLSReport , and to use that function "HasUser"declared only into TSQLBaseReport is correct or the framework does not support it. Show the following example
unit FileTables;
interface
{$I Synopse.inc}
type
TSQLFile = Class
...
end;
TSQLUser = class(TSQLFile)
...
end;
TSQLBaseReport = class(TSQLFile)
private
fUser: TSQLUserReports;
public
function HasUser(ClientDB: TSQLRestClientUri; const AUserName: RawUTF8;
const AUserID: Integer = -1): Boolean; overload;
// returned aRowID is an ID of row in PIVOT TABLE !!!
// so that we can access additional data stored in pivot connection
function HasUser(ClientDB: TSQLRestClientUri; const AUserName: RawUTF8;
const AUserID: Integer; var ARowID: Integer): Boolean; overload;virtual;Abstract;
published
property User: TSQLUserReports read fUser;
end;
TSQLUserBaseReports = class(TSQLRecordMany)
private
fSource: TSQLUser;
fDest: TSQLBaseReport;
published
property Source: TSQLUser read fSource;
property Dest: TSQLBaseReport read fDest;
end;
TSQLUserPDFReports = class(TSQLUserBaseReports)
private
fSource: TSQLUser;
fDest: TSQLPDFReport;
published
property Source: TSQLUser read fSource;
property Dest: TSQLPDFReport read fDest;
end;
TSQLUserXLSReports = class(TSQLUserBaseReports)
private
fSource: TSQLUser;
fDest: TSQLXLSReport;
published
property Source: TSQLUser read fSource;
property Dest: TSQLXLSReport read fDest;
end;
TSQLPDFReport = class(TSQLBaseReport)
private
fUsers: TSQLUserPDFReports;
published
property Users: TSQLUserPDFReports read fUsers;
end;
TSQLXLSReport = class(TSQLBaseReport)
private
fUsers: TSQLUserXLSReports;
published
property Users: TSQLUserXLSReports read fUsers;
end;
...
implementation
...
function TSQLBaseReport.HasUser(ClientDB: TSQLRestClientUri;
const AUserName: RawUTF8; const AUserID: Integer = -1): Boolean;
var
dummy: Integer;
begin
result := HasUser(ClientDB, AUserName, AUserID, dummy);
end;
function TSQLBaseReport.HasUser(ClientDB: TSQLRestClientUri;
const AUserName: RawUTF8; const AUserID: Integer;
var ARowID: Integer): Boolean;
var
User: TSQLUser;
begin
result := false;
ARowID := -1;
fUsers.FillMany(ClientDB, fID);
while fUsers.FillOne do
begin
if fUsers.Dest <> nil then
try
User := TSQLUser.Create(ClientDB, Integer(fUsers.Dest));
if ((AUserID = -1) and (User.Name = AUserName)) or
((AUserID > -1) and (User.ID = AUserID)) then
begin
result := True;
ARowID := fUsers.ID;
break;
end;
finally
FreeAndNil(User);
end;
end;
end;
In the following example the user search is performed in the table TSQLPDFReport or in the table TSQLUserBaseReports.
NB: the TSQL*Base* tables are not created in the database, only derived tables are created
Uses FileTables;
....
procedure TForm1.Button1Click(Sender: TObject);
var
ARec : TSQLXLSReport;
k:Integer;
begin
try
ARec := TSQLXLSReport.Create(ClientDB, 1);
if ARec.ID>0 then
begin
if ARec.HasUser(ClientDB,'John')>0 then
Showmessage('the 1 report is assigned to John');
end;
finally
end;
end;
Offline
Your TSQLUserPDFReports class seems to override TSQLUserBaseReports.Source/Dest properties.
This is not correct, from the OOP point of view.
You do not need to define again the properties in inherited classes.
Online
However, this only works if I cast TSQLXLSReport(ARec).Users.AddMany (ClientDB, AUser.ID, ARec.ID, true);
procedure TForm1.Button2Click(Sender: TObject);
var
ARec : TSQLXLSReport;
k:Integer;
begin
try
ARec := TSQLXLSReport.Create(ClientDB, 1);
if ARec.ID>0 then
begin
try
AUser:=TSQLUSer..Create;
AUser.Name := 'John 2'
ClientDB.Add(AUser,True);
AddUser(AUser,ARec);
finally
AUser.free;
end;
end;
finally
end;
end;
function AddUser(AUser:TSQLUSer;ARec : TSQLBaseReport;):Boolean;
begin
if not ARec.HasUser(ClientDB,AUser.Name)=0 then
ARec.Users.AddMany(ClientDB, AUser.ID, ARec.ID, true);
end;
right???
Offline
Pages: 1