HKCU\Software\Microsoft\Windows\CurrentVersion\Internet
Settings\ProxyEnable
检测是否使用代理
0
or
1
读取注册表键值
HKCU\Software\Microsoft\Windows\CurrentVersion\Internet
Settings\ProxyServer
读取代理地址和端口
数据格式:
http=127.0.0.1:8888https=127.0.0.1:8888
设置的话就不用我说了吧,直接设置属性就可以了
vars: string
begin
with IdHTTP1.ProxyParams do
begin
ProxyServer := '192.168.0.139'//代理地址
ProxyPort := 808//代理端口
ProxyUsername := ''//你的用户名
ProxyPassword := ''//你的密码
end
s :=IdHTTP1.Get('http://www.126.com')
ShowMessage(s)//验证成功,小心啊...呵呵
end
前几天刚好有个客户叫我用DELPHI帮忙写个线程例子,给你看看//主窗体
unit Unit1
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls
type
TForm1 = class(TForm)
Button1: TButton
Memo1: TMemo
Button2: TButton
Edit1: TEdit
Label1: TLabel
procedure FormCreate(Sender: TObject)
procedure Button1Click(Sender: TObject)
procedure Button2Click(Sender: TObject)
procedure FormClose(Sender: TObjectvar Action: TCloseAction)
private
{ Private declarations }
public
{ Public declarations }
end
var
Form1: TForm1
//线程列表,和Tlist差不多,多了一些多线程同步处理方法
GvThreadList : TThreadList
implementation
uses Unit2
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject)
begin
GvThreadList := TThreadList.Create
Label1.Caption := '线程数:'
Button1.Caption := '创建'
Button2.Caption := '停止'
end
procedure TForm1.Button1Click(Sender: TObject)
var
i,ICount : Integer
MyLIst : TList
MyRcThread : RcThread
begin
ICount := StrToInt(edit1.Text)
//这里不用MyList也一样,可以直接用GvThreadList.Add(P),让学习者有个LockList方法
MyList := GvThreadList.LockList
for i :=0 to ICount-1 do
begin
MyRcThread := RcThread.Create(false,memo1,'线程编号:'+IntTostr(i))
//将所创建的线程添加到列表中,方便管理
MyList.Add(MyRcThread)
end
GvThreadList.UnlockList
end
procedure TForm1.Button2Click(Sender: TObject)
var
i : integer
MyLIst : TList
MyRcThread : RcThread
begin
//多个地方同时访问一个列表时,可以用ThreadList的线程锁方法(临界),避免多线程访问变量导致变量取值出错
MyList := GvThreadList.LockList
for i := 0 to Mylist.Count -1 do
begin
MyRcThread:=MyList[0]
MyRcThread.Terminate
Mylist.Delete(0)
end
MyList.Clear
//解锁
GvThreadList.UnlockList
end
procedure TForm1.FormClose(Sender: TObjectvar Action: TCloseAction)
begin
Button2.Click
GvThreadList.Free
end
end.
//线程单元
unit Unit2
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls
//定义线程,简单的举例如何创建/调用线程,
type
RcThread = class(TThread)
private
procedure RefreshMainForm
public
MyCount: integer
MyThreadTally : string
Mymemo : Tmemo
//创建参数:线程是否挂起,MEMO,线程标记
constructor Create(CreateSuspended:Booleanmemo:TmemoThreadTally:String)reintroduce
destructor Destroy()override
protected
procedure Execute()override
end
implementation
uses Unit1
{ RcThread }
//创建
constructor RcThread.Create(CreateSuspended: Booleanmemo:TmemoThreadTally:String)
begin
MyCount := 0
Mymemo := memo
MYThreadTally :=ThreadTally
inherited Create(CreateSuspended)
end
//释放
destructor RcThread.Destroy
begin
MyMemo.Lines.Add(MyThreadTally+'释放')
inherited
end
//执行
procedure RcThread.Execute
begin
while True do
begin
//停止,可以根据自己要判断的条件去判断(if....then break)
if (self.Terminated = true) then
Free
//线程每15豪秒执行一次,以免过多占用CPU
sleep(15)
//同步
Synchronize(RefreshMainForm)
end
end
procedure RcThread.RefreshMainForm
begin
//简单举例,往传递的MEMO中写当前线程执行了第几次
Inc(MyCount)
Mymemo.Lines.Add(MyThreadTally+' 执行第'+IntToStr(MyCount)+'次')
Application.ProcessMessages
end
end.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)