Related
Hi Im doing a raffle program for my friend.Everything was going good but then when i delete a value,the result was changing... Please help me!
Example:
Listbox;
1-a
2-c
3-b
4-f
5-h
6-j
After delete line 3:
1-a
2-c
4-f
5-h
6-j
6-g
What i want:
1-a
2-c
3-f
4-h
5-j
6-g
Here are the codes:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Label1: TLabel;
ComboBox1: TComboBox;
Edit1: TEdit;
Button1: TButton;
Label2: TLabel;
ComboBox2: TComboBox;
Label3: TLabel;
Button2: TButton;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Button3: TButton;
Button4: TButton;
SaveDialog1: TSaveDialog;
OpenDialog1: TOpenDialog;
Button5: TButton;
Button6: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
b,sayac:integer;
sonkayit,deneme:integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
sayac:=0;
listbox1.MultiSelect:=true;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
sayac:=sayac+1;
b:=listbox1.Count + 1;
listbox1.Items.Add(IntToStr(b) + ' ' + edit1.Text);
edit1.Text:='';
end;
procedure TForm1.Button2Click(Sender: TObject);
var
a:integer;
kisi:string;
begin
Randomize;
a:=Random(b);
kisi:= listbox1.Items.Strings[a];
edit2.Text:=(kisi);
if combobox1.ItemIndex=0 then
begin
edit2.Visible:=true;
edit3.Visible:=false;
edit4.Visible:=false;
edit5.Visible:=false;
edit6.Visible:=false;
end;
if combobox1.ItemIndex=1 then
begin
edit2.Visible:=true;
edit3.Visible:=true;
edit4.Visible:=false;
edit5.Visible:=false;
edit6.Visible:=false;
end;
if combobox1.ItemIndex=2 then
begin
edit2.Visible:=true;
edit3.Visible:=true;
edit4.Visible:=true;
edit5.Visible:=false;
edit6.Visible:=false;
end;
if combobox1.ItemIndex=3 then
begin
edit2.Visible:=true;
edit3.Visible:=true;
edit4.Visible:=true;
edit5.Visible:=true;
edit6.Visible:=false;
end;
if combobox1.ItemIndex=4 then
begin
edit2.Visible:=true;
edit3.Visible:=true;
edit4.Visible:=true;
edit5.Visible:=true;
edit6.Visible:=true;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
savedialog1.FileName:='çekiliş';
if savedialog1.Execute then
begin
listbox1.Items.SaveToFile(savedialog1.FileName + '.txt');
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
if opendialog1.Execute then
begin
listbox1.Items.LoadFromFile(opendialog1.FileName);
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
listbox1.DeleteSelected;
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
listbox1.Clear;
end;
end.
listbox1.Items.Add(IntToStr(b) + ' ' + edit1.Text);
instead of directly adding to listbox,store both IntToStr(b) and edit1.Text seperate in two string list,and populate the listbox data from the stringlists.
also performing delete delete from the second stringlist the corresponding index,and repopulate in listbox
or you can just store the edit1.Text in a stringlist,and delete the string from stringlist that you delete from listbox . and populate the data in listbox with the index+string combination.....
I would use a virtual list box here. These are the basic steps:
Store the data in a container other than the GUI control, for instance a string list. This is good practise in any case.
Set the Style to lbVirtual.
Implement on OnData event handler for the list. It needs to return a string composed of the index, and the underlying item in your container.
When you delete an item, delete it from the string list container and call Invalidate on the list box to force a paint cycle. That paint cycle will request new values by calling OnData and your code can supply the updated text.
Whenever the underlying container is modified, you must let the control know how many items it is displaying by setting the Count property of the list box control.
Here is a very simple example:
Pascal unit
unit Unit1;
interface
uses
SysUtils, Classes, Controls, StdCtrls, Forms;
type
TForm1 = class(TForm)
List: TListBox;
Delete: TButton;
procedure FormCreate(Sender: TObject);
procedure ListData(Control: TWinControl; Index: Integer; var Data: string);
procedure DeleteClick(Sender: TObject);
private
FItems: TStringList;
end;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
c: Char;
begin
FItems := TStringList.Create;
for c := 'a' to 'z' do
FItems.Add(c);
List.Count := FItems.Count;
end;
procedure TForm1.ListData(Control: TWinControl; Index: Integer;
var Data: string);
begin
Data := Format('%d %s', [Index+1, FItems[Index]]);
end;
procedure TForm1.DeleteClick(Sender: TObject);
var
Index: Integer;
begin
for Index := FItems.Count-1 downto 0 do
if List.Selected[Index] then
FItems.Delete(Index);
List.Count := FItems.Count;
List.Invalidate;
end;
end.
Associated form file
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 303
ClientWidth = 307
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object List: TListBox
Left = 8
Top = 8
Width = 201
Height = 287
Style = lbVirtual
Anchors = [akLeft, akTop, akRight, akBottom]
MultiSelect = True
TabOrder = 0
OnData = ListData
end
object Delete: TButton
Left = 224
Top = 8
Width = 75
Height = 23
Anchors = [akTop, akRight]
Caption = 'Delete'
TabOrder = 1
OnClick = DeleteClick
end
end
my server has a list of 4 TCP connected clients . if list full , next client must reject
//Server side
unit ServerUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdThreadMgr, IdThreadMgrDefault, IdAntiFreezeBase, IdAntiFreeze,
IdUDPBase, IdUDPServer, IdBaseComponent, IdComponent, IdTCPServer,
StdCtrls, ExtCtrls,IdSocketHandle, ComCtrls, IdUDPClient, Grids,
IdTCPConnection, IdTCPClient;
type
TForm1 = class(TForm)
Panel1: TPanel;
Label3: TLabel;
Edit3: TEdit;
Button1: TButton;
IdTCPServer1: TIdTCPServer;
IdUDPServer1: TIdUDPServer;
IdAntiFreeze1: TIdAntiFreeze;
IdThreadMgrDefault1: TIdThreadMgrDefault;
StatusBar1: TStatusBar;
GroupBox2: TGroupBox;
IncomingText: TMemo;
GroupBox1: TGroupBox;
Clients_StringGrid: TStringGrid;
IdTCPClient1: TIdTCPClient;
procedure Button1Click(Sender: TObject);
procedure IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
procedure ADDTCPConn(AThread: TIdPeerThread;i:Integer);
procedure DeleteRow1(VGrid: TStringGrid; VRow: integer);
procedure InsertRow1(VGrid: TStringGrid; Str1:String; Str2:String; Str3:String);
Procedure Add_To_StringGrid(Grid:TStringGrid; Str1:String; Str2:String; Str3:String; i:Integer);
procedure FormCreate(Sender: TObject);
procedure IdTCPServer1Execute(AThread: TIdPeerThread);
procedure IdTCPServer1Connect(AThread: TIdPeerThread);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
RCount:Integer;
flag:Boolean;
IPList : TStringList;
IPList2 : TStringList;
fl: Boolean;
implementation
uses CommonUnit;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if not IdUDPServer1.Active then
begin
IdUDPServer1.DefaultPort:=1717;
IdUDPServer1.BroadcastEnabled:=True;
IdUDPServer1.Active:=True;
end;
if not IdTCPServer1.Active then
begin
IdTCPServer1.DefaultPort:=1717;
IdTCPServer1.Active:=True;
end;
end;
procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var
s : String;
ip : String;
dss : TStringStream;
begin
try
dss := TStringStream.Create('');
dss.CopyFrom(AData, AData.Size);
s := dss.DataString;
ip:=GetIPAddress();
IncomingText.Lines.Add('Client Say('+ABinding.PeerIP+'):'+s);
IncomingText.Lines.Add('------------');
ABinding.SendTo(ABinding.PeerIP, ABinding.PeerPort, ip[1], Length(ip));
dss.Free();
except
on E : Exception do
WriteLogFile(E.message);
end;
end;
procedure TForm1.ADDTCPConn(AThread: TIdPeerThread;i:Integer);
var
NewClientIP : String;
begin
NewClientIP := AThread.Connection.Socket.Binding.PeerIP;
//NewClientHostName := IPAddrToName(NewClientIP);
//Add_To_StringGrid(Clients_StringGrid,NewClientIP,'ggg','eee',i);
InsertRow1(Clients_StringGrid,NewClientIP,'ggg','eee');
IncomingText.Lines.Add(TimeToStr(Time)+' Connection from "' + 'ggg' + '" on ' + NewClientIP);
IncomingText.Lines.Add('------------');
StatusBar1.Panels.Items[0].Text := ' Status : TCP Connected';
flag:=true;
end;
Procedure TForm1.Add_To_StringGrid(Grid:TStringGrid; Str1:String; Str2:String; Str3:String;
i:Integer);
Begin
if i=-1 then
begin
if RCount <> 0 then
Grid.RowCount := Grid.RowCount + 1;
RCount:=RCount+1;
Grid.Cells[0,RCount] := Str1;
Grid.Cells[1,RCount] := Str2;
Grid.Cells[2,RCount] := Str3;
end
else
begin
Grid.Cells[0,i] := Str1;
Grid.Cells[1,i] := Str2;
Grid.Cells[2,i] := Str3;
end;
End;
procedure TForm1.InsertRow1(VGrid: TStringGrid; Str1:String; Str2:String; Str3:String);
begin
if RCount<>0 then
VGrid.RowCount:= VGrid.RowCount + 1;
VGrid.Cells[0, VGrid.RowCount - 1]:= Str1;
VGrid.Cells[1, VGrid.RowCount - 1]:= Str2;
VGrid.Cells[2, VGrid.RowCount - 1]:= Str3;
RCount:=RCount+1;
end;
procedure TForm1.DeleteRow1(VGrid: TStringGrid; VRow: integer);
var
I, J: Integer;
begin
if VGrid.RowCount = 2 then
begin
VGrid.Rows[1].CommaText:= '"","","","",""';
end
else
begin
for I:= VRow to VGrid.RowCount - 2 do
for J:=0 to VGrid.ColCount - 1 do
VGrid.Cells[J,I]:= VGrid.Cells[J, I + 1];
VGrid.RowCount:= VGrid.RowCount - 1;
end;
RCount:=RCount-1;
if RCount=0 then
VGrid.RowCount:= 2;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
RCount:=0;
Clients_StringGrid.Cells[0, 0]:= 'Client IP';
Clients_StringGrid.Cells[1, 0]:= 'Host Name';
Clients_StringGrid.Cells[2, 0]:= 'Versa';
end;
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
begin
if flag then
AThread.Connection.WriteLn('Reply')
else
AThread.Connection.WriteLn('Reject');
end;
procedure TForm1.IdTCPServer1Connect(AThread: TIdPeerThread);
var
j:Integer;
fl:Boolean;
IP:String;
IPList2 : TStringList;
Count:Integer;
i:Integer;
begin
try
Count:=StrToInt(Edit3.Text);
IP:= AThread.Connection.Socket.Binding.PeerIP;
if (Clients_StringGrid.Cols[0].IndexOf(IP) = -1) then
begin
if RCount < Count then
begin
if (Clients_StringGrid.Cols[0].IndexOf(IP) = -1) then
ADDTCPConn(AThread,-1)
else
begin
StatusBar1.Panels.Items[0].Text := ' Status : TCP Already Connected';
flag:=True;
end;
end
else
begin
IPList:=TStringList.Create;
IPList2:=TStringList.Create;
fl:=False;
IPList.Clear;
IPList2.Clear;
For i:=1 To Count Do
begin
IdTCPClient1.Host := Clients_StringGrid.Cells[0,i];
IdTCPClient1.Port := 1112;
if IdTCPClient1.connected then
IdTCPClient1.Disconnect;
try
IdTCPClient1.Connect();
IdTCPClient1.Disconnect;
IPList.Add(Clients_StringGrid.Cells[0,i]);
except
on E : Exception do
begin
IPList2.Add(Clients_StringGrid.Cells[0,i]);
fl:=True;
end;
end;
end;
IncomingText.Lines.Add('Num Act ip:'+IntToStr(IPList.Count));
For j:=1 To IPList2.Count Do
begin
IncomingText.Lines.Add('row Del'+IntToStr(Clients_StringGrid.Cols[0].IndexOf(IPList2[j-1])));
DeleteRow1(Clients_StringGrid,Clients_StringGrid.Cols[0].IndexOf(IPList2[j-1]));
end;
if fl then
begin
ADDTCPConn(AThread,-1);
flag:=True;
end
else
flag:=false;
IPList.Free;
IPList2.Free;
end;
end
else
begin
StatusBar1.Panels.Items[0].Text := ' Status : TCP Already Connected';
flag:=True;
end;
except
on E : Exception do
WriteLogFile(E.message);
end;
end;
end.
//Client Side
unit ClientUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, IdAntiFreezeBase, IdAntiFreeze,
IdTCPConnection, IdTCPClient, IdBaseComponent, IdComponent, IdUDPBase,
IdUDPClient, ComCtrls, IdUDPServer,IdSocketHandle,IdStack, IdTCPServer,
IdThreadMgr, IdThreadMgrDefault;
type
TForm2 = class(TForm)
Panel1: TPanel;
Label3: TLabel;
Edit3: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
StatusBar1: TStatusBar;
GroupBox2: TGroupBox;
IncomingText: TMemo;
IdUDPClient1: TIdUDPClient;
IdTCPClient1: TIdTCPClient;
IdAntiFreeze1: TIdAntiFreeze;
IdTCPServer1: TIdTCPServer;
IdThreadMgrDefault1: TIdThreadMgrDefault;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure IdTCPServer1Execute(AThread: TIdPeerThread);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
ServerIP:String;
implementation
uses CommonUnit;
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
if not IdUDPClient1.Active then
begin
IdUDPClient1.Port:=1717;
IdUDPClient1.BroadcastEnabled:=True;
IdUDPClient1.Active:=True;
IdTCPServer1.Active:=False;
end;
Button1.Enabled:=False;
Button2.Enabled:=True;
end;
procedure TForm2.Button2Click(Sender: TObject);
var
StrIn : String;
StrOut : String;
begin
try
StrOut:='Request';
IdUDPClient1.Broadcast(StrOut, 1717);
StrIn := IdUDPClient1.ReceiveString(100);
if not (StrIn='') then
begin
Button3.Enabled:=True;
Button2.Enabled:=False;
IncomingText.Lines.Add('UDP Reply');
StatusBar1.Panels.Items[0].Text := 'Status : UDP Connected';
ServerIP := StrIn;
end
else
WriteLogFile('UDP Connection Failed');
except
on E : Exception do
WriteLogFile(E.Message);
end;
end;
procedure TForm2.Button3Click(Sender: TObject);
var
StrIn : String;
begin
try
if ServerIP<>'' then
begin
IdTCPClient1.Host := ServerIP ;
IdTCPClient1.Port := 1717 ;
IdTCPClient1.Connect;
StrIn:= IdTCPClient1.ReadLn();
//IdTCPClient1.Disconnect;
if StrIn<>'' then
begin
IncomingText.Lines.Add(StrIn);
if StrIn<>'Reply' then
StatusBar1.Panels.Items[0].Text :='Connected To TCPServer';
else
begin
Button3.Enabled:=False;
Button1.Enabled:=True;
end;
end
else
WriteLogFile('TCP Connection Failed');
end;
except
on E : Exception do
WriteLogFile(E.message);
end;
end;
procedure TForm2.IdTCPServer1Execute(AThread: TIdPeerThread);
begin
//check point
end;
end.
//when in event onconnect on server want to check clients in list , line IdTCPClient1.Connect() return error
1)Socket Error # 10022 Invalid argument.
2)Connection Closed Gracefully.
and never run onexcute on client side
why this hapened
I firstly created a form that will show settings. Then i created a login box that will load a password from an ini file. I originally thought that it was an error with loading the ini file. Though I have isolated it to when I load the settings form. Here is the code for all of them.
The code for the settings screen:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, inifiles;
type
TForm1 = class(TForm)
SaveButton: TButton;
AEditA: TEdit;
AEditB: TEdit;
SEditB: TEdit;
PEditB: TEdit;
PLabelA: TLabel;
SLabelA: TLabel;
ALabelA: TLabel;
PEditA: TEdit;
SEditA: TEdit;
ExitButton: TButton;
Settings: TLabel;
ALabelB: TLabel;
SLabelB: TLabel;
PLabelB: TLabel;
AReserveLabel: TLabel;
BReserveLabel: TLabel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label8: TLabel;
Label7: TLabel;
procedure SaveButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ExitButtonClick(Sender: TObject);
procedure AEditAKeyPress(Sender: TObject; var Key: Char);
procedure AEditBKeyPress(Sender: TObject; var Key: Char);
procedure SEditAKeyPress(Sender: TObject; var Key: Char);
procedure SEditBKeyPress(Sender: TObject; var Key: Char);
procedure PEditAKeyPress(Sender: TObject; var Key: Char);
procedure PEditBKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
IniFile : TIniFile;
appINI : TIniFile;
APriceA : String;
SPriceA : String;
PPriceA : String;
APriceB : String;
SPriceB : String;
PPriceB : String;
implementation
{$R *.DFM}
procedure TForm1.SaveButtonClick(Sender: TObject);
//Save Button
begin
appINI := TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
APriceA := (AEditA.Text);
SPriceA := (SEditA.Text);
PPriceA := (PEditA.Text);
APriceB := (AEditB.Text);
SPriceB := (SEditB.Text);
PPriceB := (PEditB.Text);
appINI.WriteString('PricesA','Adult',APriceA);
appINI.WriteString('PricesA','Student',SPriceA);
appINI.WriteString('PricesA','Pensioner',PPriceA);
appINI.WriteString('PricesB','Adult',APriceB);
appINI.WriteString('PricesB','Student',SPriceB);
appINI.WriteString('PricesB','Pensioner',PPriceB);
appINI.Free;
ShowMessage('Settings Saved Successfully!');
end;
procedure TForm1.FormCreate(Sender: TObject);
//Displays values as the form is created
begin
{ appINI := TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
APriceA := appINI.ReadString('PricesA','Adult','');
SPriceA := appINI.ReadString('PricesA','Student','');
PPriceA := appINI.ReadString('PricesA','Pensioner','');
APriceB := appINI.ReadString('PricesB','Adult','');
SPriceB := appINI.ReadString('PricesB','Student','');
PPriceB := appINI.ReadString('PricesB','Pensioner','');
appINI.Free;
AEditA.Text := (APriceA);
SEditA.Text := (SPriceA);
PEditA.Text := (PPriceA);
AEditB.Text := (APriceB);
SEditB.Text := (SPriceB);
PEditB.Text := (PPriceB);}
end;
procedure TForm1.ExitButtonClick(Sender: TObject);
//Exit Button
begin
Close;
end;
procedure TForm1.AEditAKeyPress(Sender: TObject; var Key: Char);
var s:string;
begin
s := ('1234567890.'#8); //Add chars you want to allow
if pos(key,s) =0 then begin
Key:=#0;
showmessage('Only Numbers are allowed. Include cents!');
end;
end;
procedure TForm1.AEditBKeyPress(Sender: TObject; var Key: Char);
var s:string;
begin
s := ('1234567890.'#8); //Add chars you want to allow
if pos(key,s) =0 then begin
Key:=#0;
showmessage('Only Numbers are allowed. Include cents!');
end;
end;
procedure TForm1.SEditAKeyPress(Sender: TObject; var Key: Char);
var s:string;
begin
s := ('1234567890.'#8); //Add chars you want to allow
if pos(key,s) =0 then begin
Key:=#0;
showmessage('Only Numbers are allowed. Include cents!');
end;
end;
procedure TForm1.SEditBKeyPress(Sender: TObject; var Key: Char);
var s:string;
begin
s := ('1234567890.'#8); //Add chars you want to allow
if pos(key,s) =0 then begin
Key:=#0;
showmessage('Only Numbers are allowed. Include cents!');
end;
end;
procedure TForm1.PEditAKeyPress(Sender: TObject; var Key: Char);
var s:string;
begin
s := ('1234567890.'#8); //Add chars you want to allow
if pos(key,s) =0 then begin
Key:=#0;
showmessage('Only Numbers are allowed. Include cents!');
end;
end;
procedure TForm1.PEditBKeyPress(Sender: TObject; var Key: Char);
var s:string;
begin
s := ('1234567890.'#8); //Add chars you want to allow
if pos(key,s) =0 then begin
Key:=#0;
showmessage('Only Numbers are allowed. Include cents!');
end;
end;
//End of Settings
end.
The code for the login form:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Mask, inifiles, Unit1;
type
TForm2 = class(TForm)
PassEdit: TMaskEdit;
LoginButton: TButton;
PassLabel: TLabel;
InvisiButton: TButton;
procedure PassEditClick(Sender: TObject);
procedure LoginButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
IniFile : TIniFile;
appINI : TIniFile;
Password : string;
implementation
{$R *.DFM}
procedure TForm2.PassEditClick(Sender: TObject);
begin
PassEdit.Text := '';
end;
procedure TForm2.LoginButtonClick(Sender: TObject);
begin
//if Password = PassEdit.Text then begin
Form2.Hide;
showmessage('test');
Form1.Show;
end;
//end;
procedure TForm2.FormCreate(Sender: TObject);
begin
appINI := TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
Password := appINI.ReadString('Login','Password','');
ShowMessage(Password);
appINI.Free;
end;
end.
This is the project:
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};
{$R *.RES}
begin
Application.Initialize;
//Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm2, Form2);
Application.Run;
end.
You've commented out the line of code in the .dpr file that createsForm1`:
//Application.CreateForm(TForm1, Form1);
But you're accessing that uncreated form in Unit1:
procedure TForm2.LoginButtonClick(Sender: TObject);
begin
//if Password = PassEdit.Text then begin
Form2.Hide;
showmessage('test');
Form1.Show; // <-- Accessing uncreated form here
end;
Uncomment the line in the project file so it gets created. Note that the first form that's created with Application.CreateForm becomes your application's main form, and when that form is closed your application terminates.
You also have another major flaw in your code. You should never reference the form itself by name from within one of it's own methods, like you do here from within TForm2.LoginButtonClick:
Form2.Hide;
This means that if you ever rename the form, it won't compile, and if you create more than one TForm2, your code will either access the wrong one or will cause access violations for accessing a non-created form (like the problem you're having now). You should either just use the form's method directly, like Hide;' from the method, or useSelf.Hide;` to refer to the instance currently running the method.
(For future reference: When you have a problem, it helps if you explain what that problem is when you ask for help solving it. "Program errors" with no other information about the error is meaningless by itself. When you type "error", the very next thing you should add is the exact error you're having, including the exact error message including any address information. We can't see your screen from where we sit, so we only have the info you provide us to go by in helping you.)
My program stays running if I click the X in the top right hand corner of the form. This also happens within Delphi 4 and I am then forced to do a Program Reset as it will not recomplie if i don't.
Main form code:
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TMainForm = class(TForm)
NewButton: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
ExitButton: TButton;
LockButton: TButton;
SettingsButton: TButton;
Label1: TLabel;
TimeLabel: TLabel;
Timer1: TTimer;
procedure ExitButtonClick(Sender: TObject);
procedure LockButtonClick(Sender: TObject);
procedure SettingsButtonClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure NewButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
uses Unit2, Unit1, Unit4;
{$R *.DFM}
procedure TMainForm.ExitButtonClick(Sender: TObject);
begin
if MessageBox(0, 'Are you sure you want to quit?', 'Exit Program?', +mb_YesNo +mb_ICONWARNING) = 6 then
Application.Terminate
else
end;
procedure TMainForm.LockButtonClick(Sender: TObject);
begin
MainForm.Hide;
Login.Show;
Login.LockLabel.Visible := true;
end;
procedure TMainForm.SettingsButtonClick(Sender: TObject);
begin
MainForm.Hide;
Settings.Show;
end;
procedure TMainForm.Timer1Timer(Sender: TObject);
begin
TimeLabel.Caption := TimeToStr(time);
end;
procedure TMainForm.NewButtonClick(Sender: TObject);
begin
TransForm.Show;
MainForm.Hide;
end;
end.
Login Form code:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Mask, inifiles, Unit1;
type
TLogin = class(TForm)
PassEdit: TMaskEdit;
LoginButton: TButton;
PassLabel: TLabel;
InvisiButton: TButton;
LockLabel: TLabel;
procedure PassEditClick(Sender: TObject);
procedure LoginButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Login: TLogin;
IniFile : TIniFile;
appINI : TIniFile;
Password : string;
implementation
uses Unit3;
{$R *.DFM}
procedure TLogin.PassEditClick(Sender: TObject);
begin
PassEdit.Text := '';
end;
procedure TLogin.LoginButtonClick(Sender: TObject);
begin
if Password = PassEdit.Text then begin
Login.Hide;
MainForm.Show;
LockLabel.Visible := false;
end
else
showmessage('Incorrect Password!')
end;
procedure TLogin.FormCreate(Sender: TObject);
begin
appINI := TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
Password := appINI.ReadString('Login','Password','');
appINI.Free;
end;
end.
Setting Form Code
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, inifiles;
type
TSettings = class(TForm)
SaveButton: TButton;
AEditA: TEdit;
AEditB: TEdit;
SEditB: TEdit;
PEditB: TEdit;
PLabelA: TLabel;
SLabelA: TLabel;
ALabelA: TLabel;
PEditA: TEdit;
SEditA: TEdit;
BackButton: TButton;
SettingsLabel: TLabel;
ALabelB: TLabel;
SLabelB: TLabel;
PLabelB: TLabel;
AReserveLabel: TLabel;
BReserveLabel: TLabel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label8: TLabel;
Label7: TLabel;
procedure SaveButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BackButtonClick(Sender: TObject);
procedure AEditAKeyPress(Sender: TObject; var Key: Char);
procedure AEditBKeyPress(Sender: TObject; var Key: Char);
procedure SEditAKeyPress(Sender: TObject; var Key: Char);
procedure SEditBKeyPress(Sender: TObject; var Key: Char);
procedure PEditAKeyPress(Sender: TObject; var Key: Char);
procedure PEditBKeyPress(Sender: TObject; var Key: Char);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Settings: TSettings;
IniFile : TIniFile;
appINI : TIniFile;
APriceA : String;
SPriceA : String;
PPriceA : String;
APriceB : String;
SPriceB : String;
PPriceB : String;
change : boolean;
implementation
uses Unit3, Unit2;
{$R *.DFM}
procedure TSettings.SaveButtonClick(Sender: TObject);
//Save Button
begin
appINI := TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
APriceA := (AEditA.Text);
SPriceA := (SEditA.Text);
PPriceA := (PEditA.Text);
APriceB := (AEditB.Text);
SPriceB := (SEditB.Text);
PPriceB := (PEditB.Text);
appINI.WriteString('PricesA','Adult',APriceA);
appINI.WriteString('PricesA','Student',SPriceA);
appINI.WriteString('PricesA','Pensioner',PPriceA);
appINI.WriteString('PricesB','Adult',APriceB);
appINI.WriteString('PricesB','Student',SPriceB);
appINI.WriteString('PricesB','Pensioner',PPriceB);
appINI.Free;
ShowMessage('Settings Saved Successfully!');
change := false;
end;
procedure TSettings.FormCreate(Sender: TObject);
//Displays values as the form is created
begin
appINI := TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
APriceA := appINI.ReadString('PricesA','Adult','');
SPriceA := appINI.ReadString('PricesA','Student','');
PPriceA := appINI.ReadString('PricesA','Pensioner','');
APriceB := appINI.ReadString('PricesB','Adult','');
SPriceB := appINI.ReadString('PricesB','Student','');
PPriceB := appINI.ReadString('PricesB','Pensioner','');
appINI.Free;
AEditA.Text := (APriceA);
SEditA.Text := (SPriceA);
PEditA.Text := (PPriceA);
AEditB.Text := (APriceB);
SEditB.Text := (SPriceB);
PEditB.Text := (PPriceB);
end;
procedure TSettings.BackButtonClick(Sender: TObject);
//Exit Button
begin
if MessageBox(0, 'Are you sure you want to quit?', 'Exit Program?', +mb_YesNo +mb_ICONWARNING) = 6 then begin
if Change = (true) then
begin
if MessageBox(0, 'Save Changes?', 'Save Changes?', +mb_YesNo +mb_ICONWARNING) = 6 then
begin
appINI := TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
APriceA := (AEditA.Text);
SPriceA := (SEditA.Text);
PPriceA := (PEditA.Text);
APriceB := (AEditB.Text);
SPriceB := (SEditB.Text);
PPriceB := (PEditB.Text);
appINI.WriteString('PricesA','Adult',APriceA);
appINI.WriteString('PricesA','Student',SPriceA);
appINI.WriteString('PricesA','Pensioner',PPriceA);
appINI.WriteString('PricesB','Adult',APriceB);
appINI.WriteString('PricesB','Student',SPriceB);
appINI.WriteString('PricesB','Pensioner',PPriceB);
appINI.Free;
ShowMessage('Settings Saved Successfully!');
Settings.Hide;
MainForm.Show;
change := false;
end
else
change := false;
MainForm.Show;
Settings.Hide;
end
else
MainForm.Show;
Settings.Hide;
end
else
end;
procedure TSettings.AEditAKeyPress(Sender: TObject; var Key: Char);
var s:string;
begin
change := true;
s := ('1234567890.'#8); //Add chars you want to allow
if pos(key,s) =0 then begin
Key:=#0;
showmessage('Only Numbers are allowed. Include cents!');
end;
end;
procedure TSettings.AEditBKeyPress(Sender: TObject; var Key: Char);
var s:string;
begin
change := true;
s := ('1234567890.'#8); //Add chars you want to allow
if pos(key,s) =0 then begin
Key:=#0;
showmessage('Only Numbers are allowed. Include cents!');
end;
end;
procedure TSettings.SEditAKeyPress(Sender: TObject; var Key: Char);
var s:string;
begin
change := true;
s := ('1234567890.'#8); //Add chars you want to allow
if pos(key,s) =0 then begin
Key:=#0;
showmessage('Only Numbers are allowed. Include cents!');
end;
end;
procedure TSettings.SEditBKeyPress(Sender: TObject; var Key: Char);
var s:string;
begin
change := true;
s := ('1234567890.'#8); //Add chars you want to allow
if pos(key,s) =0 then begin
Key:=#0;
showmessage('Only Numbers are allowed. Include cents!');
end;
end;
procedure TSettings.PEditAKeyPress(Sender: TObject; var Key: Char);
var s:string;
begin
change := true;
s := ('1234567890.'#8); //Add chars you want to allow
if pos(key,s) =0 then begin
Key:=#0;
showmessage('Only Numbers are allowed. Include cents!');
end;
end;
procedure TSettings.PEditBKeyPress(Sender: TObject; var Key: Char);
var s:string;
begin
change := true;
s := ('1234567890.'#8); //Add chars you want to allow
if pos(key,s) =0 then begin
Key:=#0;
showmessage('Only Numbers are allowed. Include cents!');
end;
end;
//End of Settings
procedure TSettings.Button1Click(Sender: TObject);
begin
Settings.hide;
end;
end.
Project Data:
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Settings},
Unit2 in 'Unit2.pas' {Login},
Unit3 in 'Unit3.pas' {MainForm},
Unit4 in '..\Write to ini\Unit4.pas' {TransForm};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TLogin, Login);
Application.CreateForm(TMainForm, MainForm);
Application.CreateForm(TSettings, Settings);
Application.Run;
end.
When i close the application it stays running, can you help me fix this?
As David said, your TLogin form is being set as Application.MainForm because it is the first form create by Application.CreateForm(). You are simply hiding the TLogin form, not closing it, which is why your app does not fully exit. When you close the TMainForm form, the TLogin form is still running.
Given the code you have shown, your TMainForm form should be the only one created with Application.CreateForm(). All of your other forms should be created on an as-needed basis instead.
You have also coded Unit1, Unit2, and Unit3 (what is Unit4?) to be inter-dependant on each other when they do not need to be, so you should remove that dependancy as well. The TLogin and TSettings units should be standalone units.
Try something more like this instead:
Main form:
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TMainForm = class(TForm)
NewButton: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
ExitButton: TButton;
LockButton: TButton;
SettingsButton: TButton;
Label1: TLabel;
TimeLabel: TLabel;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure ExitButtonClick(Sender: TObject);
procedure LockButtonClick(Sender: TObject);
procedure SettingsButtonClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure NewButtonClick(Sender: TObject);
protected
procedure WndProc(var Message: TMessage); override;
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
uses
Unit2, Unit1, Unit4;
{$R *.DFM}
const
WM_LOCK = WM_USER + 100;
procedure TMainForm.FormCreate(Sender: TObject);
begin
PostMessage(Handle, WM_LOCK, 0, 0);
end;
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if Application.MessageBox('Are you sure you want to quit?', 'Exit Program?', MB_YESNO or MB_ICONWARNING) <> IDYES then
CanClose := False;
end;
procedure TMainForm.WndProc(var Message: TMessage);
begin
if Message.Msg = WM_LOCK then
LockButtonClick(nil)
else
inherited;
end;
procedure TMainForm.ExitButtonClick(Sender: TObject);
begin
Close;
end;
procedure TMainForm.LockButtonClick(Sender: TObject);
var
Login: TLogin;
begin
Login := TLogin.Create(nil);
try
Hide;
Login.LockLabel.Visible := True;
if Login.ShowModal = mrOk then
Show
else
Application.Terminate;
finally
Login.Free;
end;
end;
procedure TMainForm.SettingsButtonClick(Sender: TObject);
var
Settings: TSettings;
begin
Settings := TSettings.Create(nil);
try
Settings.ShowModal;
finally
Settings.Free;
end;
end;
procedure TMainForm.Timer1Timer(Sender: TObject);
begin
TimeLabel.Caption := TimeToStr(time);
end;
procedure TMainForm.NewButtonClick(Sender: TObject);
begin
TransForm.Show;
Hide;
end;
end.
Login form:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Mask;
type
TLogin = class(TForm)
PassEdit: TMaskEdit;
LoginButton: TButton;
PassLabel: TLabel;
InvisiButton: TButton;
LockLabel: TLabel;
procedure PassEditClick(Sender: TObject);
procedure LoginButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
uses
inifiles;
var
Password : string;
{$R *.DFM}
procedure TLogin.FormCreate(Sender: TObject);
var
appINI : TIniFile;
begin
appINI := TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
try
Password := appINI.ReadString('Login','Password','');
finally
appINI.Free;
end;
end;
procedure TLogin.PassEditClick(Sender: TObject);
begin
PassEdit.Text := '';
end;
procedure TLogin.LoginButtonClick(Sender: TObject);
begin
if Password <> PassEdit.Text then
begin
ShowMessage('Incorrect Password!')
Exit;
end;
LockLabel.Visible := False;
ModalResult = mrOk;
end;
end.
Settings Form:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TSettings = class(TForm)
SaveButton: TButton;
AEditA: TEdit;
AEditB: TEdit;
SEditB: TEdit;
PEditB: TEdit;
PLabelA: TLabel;
SLabelA: TLabel;
ALabelA: TLabel;
PEditA: TEdit;
SEditA: TEdit;
BackButton: TButton;
SettingsLabel: TLabel;
ALabelB: TLabel;
SLabelB: TLabel;
PLabelB: TLabel;
AReserveLabel: TLabel;
BReserveLabel: TLabel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label8: TLabel;
Label7: TLabel;
procedure SaveButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BackButtonClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function Changed: Boolean;
function SaveSettings: Boolean;
public
{ Public declarations }
end;
var
APriceA : String;
SPriceA : String;
PPriceA : String;
APriceB : String;
SPriceB : String;
PPriceB : String;
implementation
uses
inifiles;
{$R *.DFM}
procedure LoadSettings;
var
appINI: TIniFile;
begin
appINI := TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
try
APriceA := appINI.ReadString('PricesA','Adult','');
SPriceA := appINI.ReadString('PricesA','Student','');
PPriceA := appINI.ReadString('PricesA','Pensioner','');
APriceB := appINI.ReadString('PricesB','Adult','');
SPriceB := appINI.ReadString('PricesB','Student','');
PPriceB := appINI.ReadString('PricesB','Pensioner','');
finally
appINI.Free;
end;
end;
procedure TSettings.FormCreate(Sender: TObject);
begin
AEditA.Text := APriceA;
AEditA.Modified := False;
SEditA.Text := SPriceA;
SEditA.Modified := False;
PEditA.Text := PPriceA;
PEditA.Modified := False;
AEditB.Text := APriceB;
AEditB.Modified := False;
SEditB.Text := SPriceB;
SEditB.Modified := False;
PEditB.Text := PPriceB;
PEditB.Modified := False;
end;
function TSettings.Changed: Boolean;
begin
Result := AEditA.Modified or
SEditA.Modified or
PEditA.Modified or
AEditB.Modified or
SEditB.Modified or
PEditB.Modified;
end;
function TSettings.SaveSettings: Boolean;
var
dbl: Double;
begin
Result := TryStrToFloat(AEditA.Text, dbl) and
TryStrToFloat(SEditA.Text, dbl) and
TryStrToFloat(PEditA.Text, dbl) and
TryStrToFloat(AEditB.Text, dbl) and
TryStrToFloat(SEditB.Text, dbl) and
TryStrToFloat(PEditB.Text, dbl);
if not Result then
begin
ShowMessage('Only Numbers are allowed. Include cents!');
Exit;
end;
APriceA := AEditA.Text;
SPriceA := SEditA.Text;
PPriceA := PEditA.Text;
APriceB := AEditB.Text;
SPriceB := SEditB.Text;
PPriceB := PEditB.Text;
appINI := TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
try
appINI.WriteString('PricesA','Adult',APriceA);
appINI.WriteString('PricesA','Student',SPriceA);
appINI.WriteString('PricesA','Pensioner',PPriceA);
appINI.WriteString('PricesB','Adult',APriceB);
appINI.WriteString('PricesB','Student',SPriceB);
appINI.WriteString('PricesB','Pensioner',PPriceB);
finally
appINI.Free;
end;
AEditA.Modified := False;
SEditA.Modified := False;
PEditA.Modified := False;
AEditB.Modified := False;
SEditB.Modified := False;
PEditB.Modified := False;
ShowMessage('Settings Saved Successfully!');
Result := True;
end;
procedure TSettings.SaveButtonClick(Sender: TObject);
begin
SaveSettings;
end;
procedure TSettings.BackButtonClick(Sender: TObject);
begin
if Changed then
begin
if Application.MessageBox('Save Changes?', 'Save Changes?', MB_YESNO or MB_ICONWARNING) = IDYES then
begin
if not SaveSettings then
Exit;
end;
end;
ModalResult = mrOk;
end;
procedure TSettings.Button1Click(Sender: TObject);
begin
Close;
end;
initialization
LoadSettings;
end.
Project:
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Settings},
Unit2 in 'Unit2.pas' {Login},
Unit3 in 'Unit3.pas' {MainForm},
Unit4 in '..\Write to ini\Unit4.pas' {TransForm};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
Application.ShowMainForm := False;
Application.Run;
end.
The easiest way to to this would be to be in a close button with just one line of code:
BtnClose.click
Begin
Application.terminate;
End;
Hope that helps
im new to delphi. and also almost new to programming world.
i was made some simple post software which using idhttp module.
but when execute it , it not correctly working.
this simple program is check for my account status.
if account login successfully it return some source code which include 'top.location ='
in source, and if login failed it return not included 'top.location ='
inside account.txt is follow first and third account was alived account
but only first account can check, after first account other account can't check
i have no idea what wrong with it
ph896011 pk1089
fsadfasdf dddddss
ph896011 pk1089
following is source of delphi
if any one help me much apprecated!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP, IdCookieManager, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
IdHTTP1: TIdHTTP;
Memo1: TMemo;
IdCookieManager1: TIdCookieManager;
lstAcct: TListBox;
result: TLabel;
Edit1: TEdit;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
//procedure FormCreate(Sender: TObject);
//procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
AccList: TStringList;
IdCookie: TIdCookieManager;
CookieList: TList;
StartCnt: Integer;
InputCnt: Integer;
WordList: TStringList;
WordNoList: TStringList;
WordCntList: TStringList;
StartTime: TDateTime;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
//temp: String;
lsttemp: TStringList;
sl : tstringlist;
//userId,userPass: string;
begin
InputCnt:= 0;
WordList := TStringList.Create;
CookieList := TList.create;
IdCookie := TIdCookieManager.Create(self);
if FileExists(ExtractFilePath(Application.ExeName) + 'account.txt') then
WordList.LoadFromFile(ExtractFilePath(Application.ExeName) + 'account.txt');
WordNoList:= TStringList.Create;
WordCntList := TStringList.Create;
lsttemp := TStringList.create;
sl :=Tstringlist.Create;
try
try
for i := 0 to WordList.Count -1 do
begin
ExtractStrings([' '], [' '], pchar(WordList[i]), lsttemp);
WordNoList.add(lsttemp[0]);
//ShowMessage(lsttemp[0]);
WordCntList.add(lsttemp[1]);
//ShowMessage(lsttemp[1]);
sl.Add('ID='+ lsttemp[0]);
sl.add('PWD=' + lsttemp[1]);
sl.add('SECCHK=0');
IdHTTP1.HandleRedirects := True;
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
memo1.Text:=idhttp1.Post('http://user.buddybuddy.co.kr/Login/Login.asp',sl);
if pos('top.location =',Memo1.Text)> 0 then
begin
application.ProcessMessages;
ShowMessage('Alive Acc!');
//result.Caption := 'alive acc' ;
sleep(1000);
Edit1.Text := 'alive acc';
lsttemp.Clear;
Memo1.Text := '';
//memo1.Text := IdHTTP1.Get('https://user.buddybuddy.co.kr/Login/Logout.asp');
Sleep(1000);
end;
if pos('top.location =', memo1.Text) <> 1 then
begin
application.ProcessMessages;
ShowMessage('bad');
Edit1.Text := 'bad';
//edit1.Text := 'bad';
lsttemp.Clear;
memo1.Text := '';
sleep(1000) ;
end;
Edit1.Text := '';
end;
finally
lsttemp.free;
end;
StartCnt := lstAcct.items.Count;
StartTime := Now;
finally
sl.Free;
end;
end;
end.
Right before:
sl.Add('ID='+ lsttemp[0]);
Do:
sl.Clear;
On the first run your "SL" holds the two POST parameters, but unless you clear it on the second run, you just keep adding parameters, confusing the HTTP server you're trying to connect to!
That might not be your only problem, but that's surely one of the problems.