I need to use a forward class. The main class is a DM (TAndroidService), the completed class is just after, of course, but I am getting a "class is not yet completely defined" error. Is there any incompatibility here? I hope I am doing the wrong thing.
Maybe you can post with some code, so the question can be better understood?
ReplyDeleteWorks perfectly for me. What is the difference between your code and mine?
ReplyDeleteThis usually happens when both declarations are not in the same type keyword scope. I have seen this often in code where each type is declared with a new type keyword.
ReplyDeleteIf it is a generic type involved, you cannot create a forward class declaration for a generic typed class - unless you define a root non-generic abstract class type.
ReplyDeleteExample:
type
TMyType = class;
TMyOtherType = class
Reference: TMyType;
end;
// abstract class, not intended for instantiation
TMyType = class abstract
public
procedure Verb1; virtual; abstract;
function Verb2:Integer; virtual; abstract;
end;
type
TMyType = class(TMyType)
private
FValue: T;
public
procedure Verb1; override;
function Verb2:Integer; override;
property Value: T read FValue write FValue;
end;
Note that this also goes if the types are internal to TMyOtherType.
var
v: TMyOtherType;
begin
v.Reference := TMyType.Create;
Thank you very much!!! Now its morning here and I will take a deep look in all your comments. I am not using any FMX because I am trying to use the Android Location directly with a Service. As soon I can try I will let you know and even post a sample code. Again thank you guys for the precious feedback!
ReplyDeleteWe don't need to know what you do next especially, that's really only interesting to you. If you'd provided a simple excerpt of code that demonstrated the problem you would have had a clear answer in a few minutes.
ReplyDeleteI just arrived at home, well, here is the code. It can work OK if I ran the SAME code using a TForm, but when I need to use the TDM from a Android Service it will fail on the first line bellow (Type 'TLocationListener' is not yet completely defined).
ReplyDeletetype
TLocationListener = class;
type
TDM = class(TAndroidService)
function AndroidServiceStartCommand(const Sender: TObject; const Intent: JIntent; Flags, StartId: Integer): Integer;
procedure AndroidServiceCreate(Sender: TObject);
procedure AndroidServiceDestroy(Sender: TObject);
private
FLocationManager: JLocationManager;
locationListener: TLocationListener;
public
{ Public declarations }
destructor Destroy; override;
procedure onLocationChanged(Location: JLocation);
end;
TLocationListener = class(TJavaLocal, JLocationListener)
private
[weak]
FParent: TDM;
public
constructor Create(AParent: TDM);
procedure onLocationChanged(Location: JLocation); cdecl;
procedure onProviderDisabled(provider: JString); cdecl;
procedure onProviderEnabled(provider: JString); cdecl;
procedure onStatusChanged(provider: JString; status: Integer; extras: JBundle); cdecl;
end;
Play by the rules I posted. One type section.
ReplyDeleteJeroen Wiert Pluimers I removed the second Type statement now it compiles! It was a lack of attention :( Well, now I will check it it will work. This way I can use the Location Sensor with a Delphi Android Service. Thank YOU!! Thank you all
ReplyDeleteiT'S Alive! My Delphi service is now able to populate a Google Firebase database with Location information! Thank you all!
ReplyDelete