[fpc-pascal] Does MACRO work in this case?
silvioprog
silvioprog at gmail.com
Thu Sep 8 19:08:15 CEST 2016
Hello,
Looking an alternative to solve the problem I've talked at this topic
<http://lists.freepascal.org/pipermail/fpc-pascal/2016-August/048635.html>,
I've tried to solve it declaring a macro named "TIStringComparer.Ordinal":
=== begin code ===
{$IFDEF FPC}
function EqualityComparison(constref ALeft, ARight: string): Boolean;
begin
Result := CompareText(ALeft, ARight) = 0;
end;
function ExtendedHasher(constref AValue: string): UInt32;
var
S: string;
begin
S := LowerCase(AValue);
Result := TDefaultHashFactory.GetHashCode(Pointer(S), Length(S) *
SizeOf(Char), 0);
end;
// see http://lists.freepascal.org/pipermail/fpc-pascal/2016-August
/048635.html
{$MACRO ON}
{$DEFINE TIStringComparer.Ordinal :=
TEqualityComparer<string>.Construct(EqualityComparison,
ExtendedHasher) }
{$ENDIF}
=== end code ===
The macro is just for retro-compatibility with Delphi, allowing to use this
syntax:
GVariables := TDictionary<string, string>.Create(TIStringComparer.Ordinal);
// the macro should replace it, but ...
However, it seems the macro can't replace the original
"TIStringComparer.Ordinal" to my
"TEqualityComparer<string>.Construct(EqualityComparison,
ExtendedHasher)" definition.
So, is macro indicated to solve this kind of problem?
--
Silvio Clécio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160908/ee1b9ffd/attachment.html>
More information about the fpc-pascal
mailing list