Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 05-24-2016, 10:05 AM
lexd lexd is offline
Senior Member
 
Join Date: Feb 2015
Posts: 268
Default Making a 'class of' with objects

I'm trying to convert this code from Lazarus to Delphi
I have object TDataModuleClass - what is it what does it do

I know you have code TDataModule = class of TDataModuleClass; in code

What is it what does it do, why do you use it?

example
HTML Code:
function TMyObject.Execute: TResponse;
var
  Found: Boolean;
  i: Integer;
  dmc: TDataModuleClass;
  DataMod: TDataModule;
begin
  // Search path in main module actions
  Found:= False;
  if fPathInfo <> '' then
  begin
    Found:= SearchActionInModule(fPathInfo, TDataModule(Owner));
  end;
  DataMod:= nil;

  // Search path in other additional modules
  if (not Found) then
  for i:= 0 to High(fModules) do
  if fPathList[i].IndexOf(fPathInfo) <> -1 then
  begin
    dmc := TDataModuleClass(FindClass(fModules[i]));
    if dmc <> nil then
    begin
      DataMod:= dmc.Create(nil);
      Found:= SearchActionInModule(fPathInfo, DataMod);
    end;
    if Found then
      Break;
  end;

  // Default path /
  if (not Found) and (fPathInfo = '') and (Assigned(fOnRequest)) then
  begin
    Found:= True;
    if fRequest = nil then
      raise Exception.Create('TMyObject: Request object is not initialized');
    if fResponse = nil then
      raise Exception.Create('TMyObject: Response object is not initialized');

    fOnRequest(Self, fRequest, fResponse);
    Result:= fResponse;
  end;

  if not Found then
    fResponse.Add(fPathInfo + ' not found');

  Result:= fResponse;

  if Assigned(DataMod) then
    DataMod.Free;
end;
If I just declared above the Method

Type
TDataModule = class of TDataModuleClass;

It most probably will work, but I would like to know what I'm doing.
Reply With Quote
  #2  
Old 05-24-2016, 10:27 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,329
Default

http://docwiki.embarcadero.com/RADSt...ass_References
Reply With Quote
  #3  
Old 05-24-2016, 12:42 PM
lexd lexd is offline
Senior Member
 
Join Date: Feb 2015
Posts: 268
Default

I always understood a object has code and it also has data pacific to that object and when a 2nd object is used the one piece of code is used.

points
the compiler may not know the object at compile time but get the object type before creation of the object. meaning its a pointer to a pointer of the object.

I understand
type TCollectionItemClass = class of TCollectionItem; // well with TCollection.
TCollection has TList to store many TCollectionItem's separately.

its going a round about way with out describing the use of memory
Reply With Quote
Reply

Tags
delphi

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 06:07 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.