Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 08.12.06 14:40 
Ich möchte mit dem COM-Port arbeiten. Dazu habe ich das gefunden. Allerdings mag Delphi das "ComFile" nicht. Was muss ich da noch einbinden?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot


Zuletzt bearbeitet von Marco D. am Fr 08.12.06 21:59, insgesamt 3-mal bearbeitet
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Fr 08.12.06 21:15 
Dein Link verweißt ins Leere, ich denk mal du meinst:
www.swissdelphicente.../showcode.php?id=841

ComFile ist vom Typ THandle, siehe obere Funktion.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 08.12.06 21:58 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
function Read: string;
var
  d: array[1..80] of Char;
  s: string;
  BytesRead, i: Integer;
  ComFile: THandle;
begin
  Result := '';
  if not ReadFile(ComFile, d, SizeOf(d), BytesRead, nil) then
  begin
    { Raise an exception }
  end;
  s := '';
  for i := 1 to BytesRead do s := s + d[I];
  Result := s;
end;

Fehler: [Fehler] ComPort.pas(78): Die Typen der tatsächlichen und formalen Var-Parameter müssen übereinstimmen
Was tun?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
aim65
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 312

Win 9x, Win XP
Delphi 3pro, 7PE
BeitragVerfasst: Fr 08.12.06 23:26 
Habe das mal in der Windows.pas gefunden:
Zitat:
function ReadFile(hFile: THandle; var Buffer; nNumberOfBytesToRead: DWORD;
var lpNumberOfBytesRead: DWORD; lpOverlapped: POverlapped): BOOL; stdcall;


Könnte es sein, daß der Fehler darin liegt, daß BytesRead als Integer deklariert wird, aber die Windows-DLL ein DWORD erwartet? Nur mal geraten.
Probier auch mal "PortHandle" statt "ComFile"
Auch evtl. "d[1]" statt "d".

Edit: Habe eben mal Deine Funktion kopiert und einfach in einen ButtonClick eingebaut. Bei mir compiliert's ohne Fehlermeldung. Auch zur Laufzeit gibt's nix (krieg halt einen leeren String zurück, da ich ja nix einlese)
Der o.g. Kram wird wahrscheinlich dann auch nicht helfen.. :nixweiss:
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 09.12.06 16:06 
Habe das jetzt so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
function TComPort.Read: string;
var
  d: array[1..80] of Char;
  s: string;
  BytesRead, i: Integer;
begin
  Result := '';
  if not ReadFile(FComFile, d, SizeOf(d), dword(BytesRead), nil) then
  begin
    { Raise an exception }
  end;
  s := '';
  for i := 1 to BytesRead do s := s + d[I];
  Result := s;
end;

Und es compiliert schon mal ...

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
JDKDelphi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 115
Erhaltene Danke: 22

WIN2000, XP, WIN 7 , UNIX, LINUX
Assembler für (Z8x, 68xxx,R6000,Intel), DELPHI 6 Enterprise, MAGIC eDeveloper V9+V10, C++, C#,VB, .NET, zertifizierter iBOLT-Programmierer
BeitragVerfasst: Sa 09.12.06 18:07 
Titel: serieller Port
hallo,

ich nutze das OCX von Windows problemlos wie in VB6.

gruss

jdkdelphi
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 09.12.06 18:11 
Titel: Re: serieller Port
user profile iconJDKDelphi hat folgendes geschrieben:
hallo,

ich nutze das OCX von Windows problemlos wie in VB6.

gruss

jdkdelphi

Aha, und wo ist der Bezug zur Frage? :nixweiss:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 10.12.06 17:25 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
FComFile := CreateFile(DeviceName,
    GENERIC_READ or GENERIC_WRITE,
    0,
    nil,
    OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL,
    0);

Warum bekomme ich hier immer eine Zugriffsverletzung? FComFile ist vom Typ THandle.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: So 10.12.06 18:37 
Hier, alt aber gut:
Einloggen, um Attachments anzusehen!
_________________
Na denn, dann. Bis dann, denn.