Skupcie się na wywołaniu procedury dla Button2 - to ta procedura może sprawiać problemy.
Błąd Access Violation pojawia mi się w linijce: ofstream plik(temp);
//---------------------------------------------------------------------------
#include <vcl.h>
#include <windows.h>
#include <string>
#include <sstream>
#include <fstream.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "pies"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
//jeśli wyrazy są takie same, zwraca TRUE, w przeciwnim wypadku FALSE:
bool takie_same(char arg1[50], char arg2[50])
{
if(strcmp(arg1, arg2)==0) return true;
else return false;
}
//wyprowadza nazwę programy w danym podkluczu
String wartosc_wyswietlana(char sciezka[MAX_PATH], HKEY klucz, DWORD typ_danych, DWORD rozmiar)
{
CHAR wartosc[128];
RegOpenKeyEx(HKEY_LOCAL_MACHINE,sciezka,0,KEY_READ,&klucz);
RegQueryValueEx(klucz,"DisplayName",0,&typ_danych,(LPBYTE)wartosc,&rozmiar);
return wartosc;
}
//jeśli folder istnieje, zwraca TRUE, w przeciwnim wypadku FALSE:
bool folder_istnieje(string file)
{
DWORD returnvalue;
returnvalue = GetFileAttributes(file.c_str());
if(returnvalue == ((DWORD)-1)) return false;
else return true;
}
//jako argumenty podaje się składowe: R, B, B
int kolor(int R, int G, int B)
{
return B * 65536 + G * 256 + R;
}
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
//PRZYCISK ODPOWIADAJĄCY ZA ZAPIS DO PLIKU:
void __fastcall TForm1::Button2Click(TObject *Sender)
{
String x;
if(SaveDialog1->Execute())
{
strcpy(temp, SaveDialog1->FileName.c_str());
strcat(temp, ".txt");
ofstream plik(temp);
if(plik)
{
plik<<"[lista_zainstalowanych_programów]\n";
plik<<indeks<<endl;
for(i=0; i<indeks ;i++)
plik<<tablica[i]<<"\n";
plik.close();
String x;
x="Lista zainstalowanych programów zapisana w ";
x+=temp;
MessageBox(NULL, x.c_str(), "Gotowe", MB_ICONINFORMATION);
}
else MessageBox(NULL, "Nie można dokonać zapisu", "Problem", MB_ICONERROR);
}
}
//---------------------------------------------------------------------------
//(funkcja pobierająca dane - nie wrzuciłem bo za długie. Poza tym nie sprawia problemów.)
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
//przy zamykaniu programu, usuwane są komponenty stworzone dynamicznie
//zmienna liczba_podkluczy jest ustalona, więc to nie przez to
for (i=0; i<liczba_podkluczy; i++)
{
delete tablica[i];
delete tablica_plik[i];
}
delete [] tablica;
delete [] tablica_plik;
delete [] wpisy_zrodlo;
delete [] brakujace;
}
//---------------------------------------------------------------------------
Unit1.h:
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <Dialogs.hpp>
#include <TabNotBk.hpp>
#include <ExtCtrls.hpp>
#include <jpeg.hpp>
#include <FileCtrl.hpp>
#include "pies.h"
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TTabbedNotebook *TabbedNotebook1;
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
TLabel *Label4;
TRichEdit *RichEdit1;
TButton *Button2;
TSaveDialog *SaveDialog1;
TOpenDialog *OpenDialog1;
TImage *Image1;
TLabel *Label5;
TLabel *Label6;
TEdit *Edit1;
TButton *Button4;
TButton *Button5;
TButton *Button6;
TButton *Button7;
TRichEdit *RichEdit2;
TButton *Button8;
TLabel *Label7;
TImage *Image2;
TButton *Button9;
TScrollBox *ScrollBox1;
TImage *Image3;
void __fastcall Button2Click(TObject *Sender);
void __fastcall Button8Click(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
private:
public:
DWORD liczba_podkluczy;
unsigned int i, j, k, m, indeks, licznik, il_linijek, il_wpisow_zainst;
char temp[100];
string s, plik_desktop, nl;
//char tablica[300][100], tablica_plik[300][100];
char **tablica, **tablica_plik;
int *brakujace;
string *wpisy_zrodlo;
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif