Autor Beitrag
pmw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65



BeitragVerfasst: Sa 28.12.02 12:01 
Hallo!

Beim Beenden der Anwendung kommt immer eine Fehlermeldung 'Ungültige Zeigeroperation'. Wo liegt der Fehler?

Viele Grüße
Martin Winandy


ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
var
  Form1: TForm1;
  sFileString: AnsiString;

implementation

{$R *.dfm}

function LoadStringFromFile(sInFile: String; var sFileString: AnsiString): Boolean;
var
  FileStream: TFileStream;
begin
  Result := False;
  if not FileExists(sInFile) then Exit;
  FileStream := TFileStream.Create(sInFile, fmOpenRead);
  try
    if FileStream.Size <> 0 then begin
      SetLength(sFileString, FileStream.Size);
      FileStream.Read(sFileString[1], FileStream.Size);
      Result := True;
    end;
  finally FileStream.Free end;
end;

function SaveStringToFile(sOutFile: String; sFileString: AnsiString): Boolean;
var
  FileStream: TFileStream;
begin
  Result := False;
  FileStream := TFileStream.Create(sOutFile, fmCreate);
  try
    if Length(sFileString) <> 0 then begin
      FileStream.Write(sFileString[1], Length(sFileString));
      Result := True;
    end;
  finally FileStream.Free end;
end;

procedure TForm1.EncodeClick(Sender: TObject);
begin

  LoadStringFromFile(bmp.Text,sFileString);
 
  sFileString := 'TEST'+sFileString;

  SaveStringToFile(spf.Text,sFileString);

end;


Zuletzt bearbeitet von pmw am Sa 28.12.02 16:36, insgesamt 1-mal bearbeitet
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 28.12.02 15:56 
Was machst du in OnClose und in OnDestroy noch? Im Code sehe ich jetzt nichts, habe aber auch keinerlei Erfahrung mit TFileStream.
pmw Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65



BeitragVerfasst: Sa 28.12.02 15:59 
Hallo!

Das ist der komplette Quelltext. Ich habe nur den Code, den Delphi selbst erzeugt rausgenommen. Bei OnClose und in OnDestroy habe ich garnichts eingegeben.

Viele Grüße
Martin Winandy
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Sa 28.12.02 16:09 
Mach mal die Deklaration der DLL oben raus und probiers dann nochmal, wenn der Fehler dann immer noch kommt, liegst woanners. Wenn nicht, dann würde ich mir die Funktion der DLL mal genauer ansehen
pmw Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65



BeitragVerfasst: Sa 28.12.02 16:36 
Hallo!

Dies ändert leider auch nichts!

Viele Grüße
Martin Winandy
bis11
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1247
Erhaltene Danke: 2

Apple Mac OSX 10.11

BeitragVerfasst: Sa 28.12.02 16:42 
Hi,

in welcher Zeile kommt denn der Fehler ? Ich vermute, es liegt and Deiner Procedure "EncodeClick" aber um genaueres zu sagen, brauche ich die Zeile wo der Fehler auftritt.
pmw Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65



BeitragVerfasst: Sa 28.12.02 17:41 
Hallo!

Auch wenn ich aus dem Code (fast) alles rausnehme kommt noch der Fehler (immer ohne Zeilenangabe).

ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Spin;

type
  TForm1 = class(TForm)
    bmp: TEdit;
    Label1: TLabel;
    spf: TEdit;
    Label2: TLabel;
    Encode: TButton;
    Image1: TImage;
    Label3: TLabel;
    color: TComboBox;
    Label4: TLabel;
    filesize: TSpinEdit;
    procedure EncodeClick(Sender: TObject);
  private
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.EncodeClick(Sender: TObject);
begin

end;

end.


Zuletzt bearbeitet von pmw am Sa 28.12.02 18:37, insgesamt 2-mal bearbeitet
bis11
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1247
Erhaltene Danke: 2

Apple Mac OSX 10.11

BeitragVerfasst: Sa 28.12.02 17:50 
Und wenn Du das auch noch rausnimmst sFileString: AnsiString; ?
pmw Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65



BeitragVerfasst: Sa 28.12.02 18:37 
Hallo!

Wen ich ShareMem im Programm UND in der DLL rausnehme, dann gibt es zwar beim Beenden des Programmes keine Fehlermeldung mehr, aber dafür funktioniert die DLL dann nicht mehr richtig!

Viele Grüße
Martin Winandy
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Sa 28.12.02 18:57 
Du hast hoffentlich ShareMem als aller erste Unit in dein Programm und die DLL eingebunden. Also am besten in der .dpr-Datei als erste Unit einbinden.

_________________
Ist Zeit wirklich Geld?
pmw Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65



BeitragVerfasst: Sa 28.12.02 19:41 
Hallo!

Ich habe ShareMem normal unter "uses" eingebunden:

Programm (Unit1):
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
unit Unit1;

interface

uses
  ShareMem, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Spin;


DLL:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
library spf_en;

uses
  ShareMem,
  SysUtils,
  Classes;


Die Datei wird richtig gespeichert und es gibt dabei auch keine Fehlermeldung. Der Fehler kommt nur beim Beenden des Programms.
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Sa 28.12.02 19:54 
Vor der Unit1 wird in der .dpr Datei noch die Unit Forms eingebunden, die noch mit dem falschen Speichermanager beim Programmstart arbeitet. Beim Beenden hingegen ist der Speichermanager der BorlandMM.dll (ShareMem) für das freigeben zuständig. Und der finalization Teil der Forms Unit versucht nun eben den belegten Speicher (Application, Screen, Mouse) mit dem falschen Speichermanager freizugeben.

Ändere das Hauptprogramm so um:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
program MyPrg;
uses
  ShareMem,
  Forms,
  Unit1 in 'Unit1.pas' {TForm1};

begin
...

_________________
Ist Zeit wirklich Geld?
pmw Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65



BeitragVerfasst: Sa 28.12.02 19:56 
DANKE!!! Das Programm läuft jetzt einwandfrei.