OK, I’m trying to use mapped types to wrap some array handling for cross platform use. We’re getting some odd results. Sample Java project (which is FAR from complete), which generates more errors than the .NET version. I’ve implemented both the mapped type (for ArrayList) and as plain arrays. The comments explain the errors and their locations.
namespace TextConApp;
interface
uses
java.util;
type
ConsoleApp = class
public
class method Main(args: array of String);
fResIDs_0Base: StrResourceArrayList0;
fNumItems: LongInt;
end;
AccArrayList<E> = public class mapped to ArrayList<E>
public
method add(element: E); mapped to add(element); // Boolean;
property Item[i: Integer]: E read mapped[i] write mapped[i]; default;
end;
AccArray<E> = public class mapped to array of E
public
property Item[i: Integer]: E read mapped[i] write mapped[i]; default;
end;
StrResInfo = public record
public
resStringIndex: LongInt;
END;
ResInfoArrayList0 = AccArrayList<StrResInfo>;
ResInfoArray0 = array of StrResInfo;
StrResource = public RECORD
public
numItems: LongInt;
theItems_0Base: ResInfoArrayList0;
END;
StrResourceArrayList0 = AccArrayList<StrResource>;
StrResource2 = public RECORD
public
numItems: LongInt;
theItems_0Base: ResInfoArray0;
END;
StrResourceArray0 = array of StrResource2;
TStrResourceArrayListMapped = public class
public
fResIDs_0Base: StrResourceArrayList0;
fNumItems, fNumPointers: LongInt;
procedure DoSomething;
end;
TStrResourceArray = public class
public
fResIDs_0Base: StrResourceArray0;
fNumItems, fNumPointers: LongInt;
procedure DoSomething;
end;
implementation
class method ConsoleApp.Main(args: array of String);
begin
System.out.println('Hello World.');
end;
procedure TStrResourceArrayListMapped.DoSomething;
var
myStrResInfo: StrResInfo;
myStrResource: StrResource;
begin
fNumItems := 0;
fNumPointers := 0;
// NOTE: Project has 'Allow Legacy "with"' checked.
// What we want to work:
with fResIDs_0Base[pred(fNumItems)] do
// This generates (E111) Variable expected in both Java and .NET
theItems_0Base[pred(numItems)].resStringIndex := fNumPointers;
// Which is essentially:
// This generates (E111) Variable expected in both Java and .NET
fResIDs_0Base[pred(fNumItems)].theItems_0Base[pred(fResIDs_0Base[pred(fNumItems)].numItems)].resStringIndex := fNumPointers;
// What I thought might work via casting:
// This generates (E111) Variable expected in both Java and .NET
StrResInfo(StrResource(fResIDs_0Base[pred(fNumItems)]).theItems_0Base[pred(fResIDs_0Base[pred(fNumItems)].numItems)]).resStringIndex := fNumPointers;
// What compiles:
// This compiles in both Java and .NET
myStrResource := fResIDs_0Base[pred(fNumItems)];
myStrResInfo := myStrResource.theItems_0Base[pred(myStrResource.numItems)];
myStrResInfo.resStringIndex := fNumPointers;
end;
procedure TStrResourceArray.DoSomething;
var
myStrResInfo: StrResInfo;
myStrResource2: StrResource2;
begin
fNumItems := 0;
fNumPointers := 0;
// What we want to work:
with fResIDs_0Base[pred(fNumItems)] do
// This compiles in both Java and .NET
theItems_0Base[pred(numItems)].resStringIndex := fNumPointers;
// Which is essentially:
// This compiles in both Java and .NET
fResIDs_0Base[pred(fNumItems)].theItems_0Base[pred(fResIDs_0Base[pred(fNumItems)].numItems)].resStringIndex := fNumPointers;
// What works:
// This compiles in both Java and .NET
myStrResource2 := fResIDs_0Base[pred(fNumItems)];
myStrResInfo := myStrResource2.theItems_0Base[pred(myStrResource2.numItems)];
myStrResInfo.resStringIndex := fNumPointers;
end;
end.
Thots?