小弟初学delphi,问题多多,望指教~ ( 积分: 50 )

  • 主题发起人 主题发起人 yaoxing
  • 开始时间 开始时间
Y

yaoxing

Unregistered / Unconfirmed
GUEST, unregistred user!
这是原程序:
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
procedure FormResize(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure DoInvisible;
procedure Dovisible;
public
{ Public declarations }
end;

procedure TForm1.DoInvisible;
var
Form1: TForm1;
Acontrol:Tcontrol;
controlcount,clientheight,ClientWidth,width,height,clientrgn,ctlrgn,FullRgn,a,margin,x,y ,ctlx,ctly:integer;
begin
margin:=(width-ClientWidth) div 2;
FullRgn:=CreateRectRgn(0,0,width,height);
x:=margin;
y:=height-clientheight-margin;
clientrgn:=createrectrgn(x,y,x+clientwidth,y+clientheight);
combinergn(fullrgn,fullrgn,clientrgn,rgn_diff);
for a:=0 to controlcount-1 do begin
acontrol:=controls[a];
if (acontrol is twincontrol) or (acontrol is tgraphiccontrol)
then with acontrol do begin
if visible then begin
ctlx:=x+left;
ctly:=y+top;
ctlrgn:=createrectrgn(ctlx,ctly,ctlx+width,ctly+height);
combinergn(fullrgn,fullrgn,ctlrgn,rgn_or);
end;
procedure Tform1.Dovisible;
begin
fullrgn:=createrectrgn(0,0,width,height);
combinergn(fullrgn,fullrgn,fullrgn,rgn_copy);
setwindowrgn(handle,fullrgn,true);
end;

implementation

{$R *.dfm}

procedure TForm1.FormResize(Sender: TObject);
begin
if button1.caption='show' then
doinvisible
else
dovisible;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
deleteobject(clientrgn);
deleteobject(fullrgn);
deleteobject(ctlrgn);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if Button.caption='show' then begin
Dovisible;
Button1.caption:='hide';
end
else begin
Doinvisible;
button1.caption:='show';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
application.Terminate;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DoInvisible;
end;

end.

报错信息:
[Error] Unit1.pas(28): Identifier redeclared: 'TForm1.DoInvisible'
[Error] Unit1.pas(32): Statements not allowed in interface part
[Error] Unit1.pas(40): '.' expected but '[' found
[Error] Unit1.pas(49): Statement expected but 'PROCEDURE' found
[Error] Unit1.pas(50): Identifier redeclared: 'TForm1.Dovisible'
[Error] Unit1.pas(53): Undeclared identifier: 'handle'
[Error] Unit1.pas(77): Undeclared identifier: 'Button'
[Error] Unit1.pas(85): Statement expected but 'PROCEDURE' found
[Error] Unit1.pas(21): Unsatisfied forward or external declaration: 'TForm1.DoInvisible'
[Error] Unit1.pas(22): Unsatisfied forward or external declaration: 'TForm1.Dovisible'
[Fatal Error] Project1.dpr(5): Could not compile used unit '../../examples/Unit1.pas'
请指教!
 
这是原程序:
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
procedure FormResize(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure DoInvisible;
procedure Dovisible;
public
{ Public declarations }
end;

procedure TForm1.DoInvisible;
var
Form1: TForm1;
Acontrol:Tcontrol;
controlcount,clientheight,ClientWidth,width,height,clientrgn,ctlrgn,FullRgn,a,margin,x,y ,ctlx,ctly:integer;
begin
margin:=(width-ClientWidth) div 2;
FullRgn:=CreateRectRgn(0,0,width,height);
x:=margin;
y:=height-clientheight-margin;
clientrgn:=createrectrgn(x,y,x+clientwidth,y+clientheight);
combinergn(fullrgn,fullrgn,clientrgn,rgn_diff);
for a:=0 to controlcount-1 do begin
acontrol:=controls[a];
if (acontrol is twincontrol) or (acontrol is tgraphiccontrol)
then with acontrol do begin
if visible then begin
ctlx:=x+left;
ctly:=y+top;
ctlrgn:=createrectrgn(ctlx,ctly,ctlx+width,ctly+height);
combinergn(fullrgn,fullrgn,ctlrgn,rgn_or);
end;
procedure Tform1.Dovisible;
begin
fullrgn:=createrectrgn(0,0,width,height);
combinergn(fullrgn,fullrgn,fullrgn,rgn_copy);
setwindowrgn(handle,fullrgn,true);
end;

implementation

{$R *.dfm}

procedure TForm1.FormResize(Sender: TObject);
begin
if button1.caption='show' then
doinvisible
else
dovisible;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
deleteobject(clientrgn);
deleteobject(fullrgn);
deleteobject(ctlrgn);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if Button.caption='show' then begin
Dovisible;
Button1.caption:='hide';
end
else begin
Doinvisible;
button1.caption:='show';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
application.Terminate;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DoInvisible;
end;

end.

报错信息:
[Error] Unit1.pas(28): Identifier redeclared: 'TForm1.DoInvisible'
[Error] Unit1.pas(32): Statements not allowed in interface part
[Error] Unit1.pas(40): '.' expected but '[' found
[Error] Unit1.pas(49): Statement expected but 'PROCEDURE' found
[Error] Unit1.pas(50): Identifier redeclared: 'TForm1.Dovisible'
[Error] Unit1.pas(53): Undeclared identifier: 'handle'
[Error] Unit1.pas(77): Undeclared identifier: 'Button'
[Error] Unit1.pas(85): Statement expected but 'PROCEDURE' found
[Error] Unit1.pas(21): Unsatisfied forward or external declaration: 'TForm1.DoInvisible'
[Error] Unit1.pas(22): Unsatisfied forward or external declaration: 'TForm1.Dovisible'
[Fatal Error] Project1.dpr(5): Could not compile used unit '../../examples/Unit1.pas'
请指教!
 
你买本书,好好看看
 
兄弟你要别人帮你改么也把你的程序要干什么说一下啊!!!!你把原程序一贴别人怎么看啊光有出错信息也没用啊!!改通可以可是不是你要达到的要求撒.
[:)]
 
这些错误很简单的,泥好好看看书吧^_^
 
双击错误,然后看提示的内容,找到相应的内容改改试试.多试几次就会了.!
 
本程序实现透明窗体效果,我是初学,书我当然知道看的啊,到论坛来难道是让你教我看书来的啊
'TForm1.Dovisible''TForm1.Dovisible'不是定义了么,怎么还提示错误啊
Statements not allowed in interface part是什么意思啊
不是用'['符号用什么符号呢
'handle'和'Button如何定义
 
我刚给你看了下书......朋友你好惨哦...实现透明窗体效果只要改两个属性就行拉
procedure TForm1,formcreate(sender:tobject);
begin
form1.brush.style:=bsclear;
form1.borderstryle:=bsnone;
end;
这就好拉....哈哈...

不过还有个小问题就是当有重画发生时透明的地方会显示其他的内容..

所以在加点东东...

type
tform=class(tform)
....
....
procedure createparams(var params:tcreateparams);override; (把这句加到type里面去)
.......
......
implementation
......
procedure tform1.createparams(var params:tcreateparams);
begin
inherited createparams(params);
params.extyle:=WS_EX_TRANSPARENT;
end;

这就全拉...朋友你下次是要多看点技术书...呵呵
 
楼上的兄弟很感谢你的帮助,不过我是把透明窗体加到2个button的click事件里面,而且我的目的并不是要以最简易的方式达到什么效果,我就是想要知道自己的原程序错在哪里了:)哪里要改动的
 
后退
顶部