Note that there are some explanatory texts on larger screens.

plurals
  1. POoverload operator and conversion type
    primarykey
    data
    text
    <p>i have a problem about conversion of type using overload of operator, here i have an full example code:</p> <pre><code>program OVerloads; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; type TMyRange = record private type TMyRangeEnum = 1 .. 90; var FMyRangeEnum: TMyRangeEnum; public class operator Implicit(const Value: Integer): TMyRange; class operator Implicit(const Value: TMyRange): Integer; class operator Explicit(const Value: Integer): TMyRange; class operator Explicit(const Value: TMyRange): Integer; end; class operator TMyRange.Implicit(const Value: Integer): TMyRange; begin Result.FMyRangeEnum := Value; end; class operator TMyRange.Implicit(const Value: TMyRange): Integer; begin Result := Value.FMyRangeEnum; end; class operator TMyRange.Explicit(const Value: Integer): TMyRange; begin Result.FMyRangeEnum := Value; end; class operator TMyRange.Explicit(const Value: TMyRange): Integer; begin Result := Value.FMyRangeEnum; end; var MyValue: TMyRange; MyVar: TMyRange; // (or Integer, not change nothing) MyArr: array[1..90] of TMyRange; // (or Integer, not change nothing) begin try { TODO -oUser -cConsole Main : Insert code here } MyValue := 90; Writeln(MyValue); // [1] Not work, error: E2054 Illegal in Write/Writeln statement Writeln(Integer(MyValue)); // Work MyVar := MyArr[MyValue]; // Not work, error: E2010 Incompatible types: 'Integer' and 'TMyRange' MyVar := MyArr[Integer(MyValue)]; // work except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; Readln; end. </code></pre> <p>Probably i have forgotten something, but as i can solve problem [1] in mnode that not need explicit all time Integer(myValue) ? Thanks again, very much.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload