Autor Beitrag
jahuer1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Mo 14.02.05 18:29 
Ich habe ein Package erstellt mit einer unit myInterface.pas. Dort sind im Interface-Teil diverse Konstanten und Typen definiert. Bsp:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
interface myInterface;

uses
   ...

const
  c1 = $00000000;
  c2 = $00000001;
  c3 = $00000002;
  c4 = $00000003;

type
   TmyTyp1 = c1..c4;


Ich habe nun mein Package kompiliert und binde es als Referenz in mein Hauptprogramm ein. Dort definiere ich eine lokale Variable vom Typ TmyTyp1. Diese soll nun mit dem Wert c1 initialisiert werden. Also etwa so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
   v1 : myInterface.TmyTyp1;

procedure init;
begin
   ...
   v1:=myInterface.c1;
   ...
end;



Das Problem:
Als mögliche, zu verwendende Werte für eine Variable vom Typ TmyTyp1 gibt mir nun die IDE nur einen Bereich MinValue..MaxValue an - und nicht c1..c4! :( Ein Wert c1 etc. wird auch nicht akzeptiert, wenn man ihn mal so reinschreibt (entweder "nicht bekannt" oder "inkompatibler Typ"). Auch wenn man mit dem Cursor auf die Variablendeklaration geht und die Typ-Info im Hint abfragt, kriegt man den (falschen) Bereich MinValue..MaxValue angezeigt.

Wo liegt das Problem?

Moderiert von user profile iconUGrohne: Code- durch Delphi-Tags ersetzt.
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Mo 14.02.05 18:34 
Ist ja klar: v1 ist vom Typ TmyTyp1, c1 nicht.

AXMD
jahuer1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Mo 14.02.05 19:13 
Jein!

0. In Delphi 7 (und vorher) lief dies immer ohne Probleme (und es gibt wohl kaum eine Typ-striktere Sprache
als Delphi...[Grüsse an Prof. Wirth!])

1. TmyTyp bezeichnet ja einen Bereich (c1..c4). In "init" mache ich eine Zuweisung aus diesem Bereich. Was
wäre daran nicht typenkonform?

Zudem: Wenn ich die Konstanten in der gleichen Unit definiere wie TmyTyp1, so kann ich nicht auf die Konstanten zugreifen, obwohl sie im interface-Teil stehen. Das finde ich auch nicht ganz normal!
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Mo 14.02.05 19:16 
c1 ist Integer, v1 ist dein "eigener" Typ. da v1 komplett in den Integer-Typ passt, meldet der Compiler auch nichts ;). Du kannst ja einem Integer auch eine Word-Variable zuweisen ;)

AXMD