Delphi: Components and Controls do not work with Frame
I open a demo (ICS - SingleD). There are regular controls (edits, labels, panels, buttons, memos) and a component to download files from the Internet.
I want to move them all into a frame.
I create a Frame and:
1) Cut all controls except the component from a main form and paste them into a Frame. Then I change a code for the new frame's controls (e.g. just to cut "Form1" from "Form1.URLEdit.Text" - it will be used in the frame, or to add "Frame11": Frame11.ProgressBar, so it will work from a main form).
Result: the component does not show necessary information in a memo, in a progress bar etc. Nothing happens on the component's events (even if to write "deletefile('1.txt')). Events of visual controlsdo not work (e.g. OnEdit1Change).
2) Cut all controls and the component, paste them into a Frame (all code is changed to work in the Frame).
Result: one button work, another - no and etc. Even if to write MainForm.Caption:='xxx' - on a button's click then nothing will happen. If to create a new button and to write the same code - all will work.
E.G. TFrame1.btnStopClick does not work here:
MAIN FORM
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, clDownLoader, clWinInet, clDC, clDCUtils, clMultiDC, clSingleDC,
clProgressBar, ExtCtrls, ComCtrls, Unit1;
type
TDownLoaderTest = class(TForm)
Frame11: TFrame1;
// procedure btnDownLoadClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Button1Click(Sender: TObject);
procedure Frame11Button2Click(Sender: TObject);
{ procedure btnGetInfoClick(Sender: TObject);
procedure btnStopClick(Sender: TObject);
procedure edtFileChange(Sender: TObject);
procedure edtUserChange(Sender: TObject);
procedure edtPasswordChange(Sender: TObject);
procedure edtURLChange(Sender: TObject);
procedure edtDirectoryChange(Sender: TObject);}
// procedure Button1Click(Sender: TObject);
// procedure edtThreadCountChange(Sender: TObject);
// procedure edtBufferSizeChange(Sender: TObject);
private
public
end;
var
DownLoaderTest: TDownLoaderTest;
implementation
{$R *.DFM}
procedure TDownLoaderTest.Button1Click(Sender: TObject);
begin
DownLoaderTest.Caption:='1111';
deletefile('aaa');
end;
procedure TDownLoaderTest.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
// CanClose := not Frame11.clDownLoader1.IsBusy;
end;
procedure TDownLoaderTest.Frame11Button2Click(Sender: TObject);
begin
Frame11.Button1Click(Sender);
end;
end.
FRAME
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, clMultiDC, clSingleDC, clDownLoader, ComCtrls, StdCtrls,
clProgressBar,clWinInet, clDC, clDCUtils;
type
TFrame1 = class(TFrame)
btnDownLoad: TButton;
btnGetInfo: TButton;
btnStop: TButton;
clProgressBar1: TclProgressBar;
edtBufferSize: TEdit;
edtDirectory: TEdit;
edtFile: TEdit;
edtPassword: TEdit;
edtStatistic: TEdit;
edtThreadCount: TEdit;
edtURL: TEdit;
edtUser: TEdit;
Label1: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
memErrors: TMemo;
memInfo: TMemo;
memPreview: TMemo;
updBufferSize: TUpDown;
updThreadCount: TUpDown;
clDownLoader1: TclDownLoader;
Button1: TButton;
Button2: TButton;
procedure btnDownLoadClick(Sender: TObject);
procedure btnGetInfoClick(Sender: TObject);
procedure btnStopClick(Sender: TObject);
procedure edtFileChange(Sender: TObject);
procedure edtUserChange(Sender: TObject);
procedure edtPasswordChange(Sender: TObject);
procedure edtURLChange(Sender: TObject);
procedure edtDirectoryChange(Sender: TObject);
procedure edtThreadCountChange(Sender: TObject);
procedure edtBufferSizeChange(Sender: TObject);
procedure clDownLoader1DataItemProceed(Sender: TObject;
ResourceInfo: TclResourceInfo; AStateItem: TclResourceStateItem;
CurrentData: PAnsiChar; CurrentDataSize: Integer);
procedure clDownLoader1UrlParsing(Sender: TObject;
var URLComponents: URL_COMPONENTS);
procedure clDownLoader1StatusChanged(Sender: TObject;
Status: TclProcessStatus);
procedure clDownLo开发者_Go百科ader1Changed(Sender: TObject);
procedure clDownLoader1GetResourceInfo(Sender: TObject;
ResourceInfo: TclResourceInfo);
procedure clDownLoader1DataTextProceed(Sender: TObject; Text: TStrings);
procedure clDownLoader1Error(Sender: TObject; const Error: string;
ErrorCode: Integer);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
uses main;
var FIsLoading: Boolean;
{$R *.dfm}
procedure TFrame1.btnDownLoadClick(Sender: TObject);
begin
memInfo.Lines.Clear();
memErrors.Lines.Clear();
clDownLoader1.Start(True);
end;
procedure TFrame1.btnGetInfoClick(Sender: TObject);
begin
memInfo.Lines.Clear();
memErrors.Lines.Clear();
clDownLoader1.GetResourceInfo(True);
end;
//////// btnStopClick Does NOT work!!!!
procedure TFrame1.btnStopClick(Sender: TObject);
begin
DownLoaderTest.Caption:='sss';
clDownLoader1.Stop();
end;
//////// btnStopClick WORKS!!!!!!!!
procedure TFrame1.Button1Click(Sender: TObject);
begin
DownLoaderTest.Caption:='1111';
clDownLoader1.Stop();
end;
procedure TFrame1.clDownLoader1Changed(Sender: TObject);
begin
if FIsLoading then Exit;
FIsLoading := True;
try
edtURL.Text := clDownLoader1.URL;
edtUser.Text := clDownLoader1.UserName;
edtPassword.Text := clDownLoader1.Password;
edtFile.Text := clDownLoader1.LocalFile;
edtDirectory.Text := clDownLoader1.LocalFolder;
updThreadCount.Position := clDownLoader1.ThreadCount;
updBufferSize.Position := clDownLoader1.BatchSize;
finally
FIsLoading := False;
end;
end;
procedure TFrame1.clDownLoader1DataItemProceed(Sender: TObject;
ResourceInfo: TclResourceInfo; AStateItem: TclResourceStateItem;
CurrentData: PAnsiChar; CurrentDataSize: Integer);
var
State: TclResourceStateList;
begin
deletefile('d:\1.rar');
State := AStateItem.ResourceState;
edtStatistic.Text := Format('%.2n of %.2n Kb proceed, speed %.2n Kb/sec, elapsed %.2n min, remains %.2n min',
[State.BytesProceed / 1024, State.ResourceSize / 1024, State.Speed / 1024,
State.ElapsedTime / 60, State.RemainingTime / 60]);
end;
procedure TFrame1.clDownLoader1DataTextProceed(Sender: TObject; Text: TStrings);
begin
memPreview.Lines.Assign(Text);
end;
procedure TFrame1.clDownLoader1Error(Sender: TObject; const Error: string;
ErrorCode: Integer);
begin
memErrors.Lines.Text := (Sender as TclDownLoader).Errors.Text;
end;
procedure TFrame1.clDownLoader1GetResourceInfo(Sender: TObject;
ResourceInfo: TclResourceInfo);
var
s: String;
begin
if (ResourceInfo <> nil) then
begin
s := 'Resource ' + ResourceInfo.Name + '; Size ' + IntToStr(ResourceInfo.Size)
+ '; Date ' + DateTimeToStr(ResourceInfo.Date)
+ '; Type ' + ResourceInfo.ContentType;
if ResourceInfo.Compressed then
begin
s := s + '; Compressed';
end;
end else
begin
s := 'There are no any info available.';
end;
memInfo.Lines.Add(s);
end;
procedure TFrame1.clDownLoader1StatusChanged(Sender: TObject;
Status: TclProcessStatus);
var
s: String;
begin
case Status of
psSuccess: MessageBox(0, 'Process completed successfully', 'Message', 0);
psFailed:
begin
s := (Sender as TclDownLoader).Errors.Text;
MessageBox(0, PChar(s), 'Error', 0);
end;
psTerminated: MessageBox(0, 'Process stopped', 'Message', 0);
psErrors: MessageBox(0, 'Process completed with some warnings', 'Message', 0);
end;
end;
procedure TFrame1.clDownLoader1UrlParsing(Sender: TObject;
var URLComponents: URL_COMPONENTS);
begin
with URLComponents do
begin
memInfo.Lines.Add('Scheme: ' + lpszScheme);
memInfo.Lines.Add('Host: ' + lpszHostName);
memInfo.Lines.Add('User: ' + lpszUserName);
memInfo.Lines.Add('Path: ' + lpszUrlPath);
memInfo.Lines.Add('Extra: ' + lpszExtraInfo);
end;
end;
procedure TFrame1.edtBufferSizeChange(Sender: TObject);
begin
if FIsLoading then Exit;
clDownLoader1.BatchSize := updBufferSize.Position;
end;
procedure TFrame1.edtDirectoryChange(Sender: TObject);
begin
if FIsLoading then Exit;
clDownLoader1.LocalFolder := edtDirectory.Text;
end;
procedure TFrame1.edtFileChange(Sender: TObject);
begin
if FIsLoading then Exit;
clDownLoader1.LocalFile := edtFile.Text;
end;
procedure TFrame1.edtPasswordChange(Sender: TObject);
begin
if FIsLoading then Exit;
clDownLoader1.Password := edtPassword.Text;
end;
procedure TFrame1.edtThreadCountChange(Sender: TObject);
begin
if FIsLoading then Exit;
clDownLoader1.ThreadCount := updThreadCount.Position;
end;
procedure TFrame1.edtURLChange(Sender: TObject);
begin
if FIsLoading then Exit;
clDownLoader1.URL := edtURL.Text;
end;
procedure TFrame1.edtUserChange(Sender: TObject);
begin
if FIsLoading then Exit;
clDownLoader1.UserName := edtUser.Text;
end;
end.
What wrong I do with frames? It is not a problem of components or controls.
Thanks!
As a result of cut & paste, the button and it's click handler is not associated in the .dfm of the frame.
Select 'btnStop' of the frame in the design editor, click on the 'Events' tab of the OI, select 'OnClick' and click the down arrow at the right side, find and select 'btnStopClick' from the list.
精彩评论