Delphi TImage Loading GIF Bad Qality - delphi

While a process is running in the background, I show a loading animation on the screen. But the GIF looks very bad quality. How can I fix this problem?
unit Unit3;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Imaging.GIFImg, Vcl.ExtCtrls,
Vcl.StdCtrls;
type
TForm3 = class(TForm)
Image1: TImage;
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
var
sFile: string;
end;
var
Form3: TForm3;
aGIF: TGIFImage;
bmp:TBitmap;
implementation
{$R *.dfm}
procedure TForm3.FormShow(Sender: TObject);
begin
aGIF := TGIFImage.Create;
aGIF.LoadFromFile(sFile);
aGIF.Animate := True;
Image1.Picture.Assign(aGIF);
aGIF.Free;
end;
end.

Related

How in Delphi to make the frame completely overlap the form on which it is located (given the fact that the form can be scrolled)?

There are several frames in my application. All of them are located on the form - on the main. In some frames, the height can be very large, so it should be possible to scroll the form on which such frames are located. I set the autoscroll flag to true for the main form, on which all the frames are located. And wrote the following code - so that the height and width of the frames correspond to the form.
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Unit3;
type
TForm1 = class(TForm)
Frame31: TFrame3;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure SetPosition;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
SetPosition;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
SetPosition;
end;
procedure TForm1.SetPosition;
begin
Frame31.Left := 0;
Frame31.Top := 0;
Frame31.Width := Form1.Width;
Frame31.Height := Form1.Height;
end;
end.
Here is the code for one of the frames.
unit Unit3;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
type
TFrame3 = class(TFrame)
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
{$R *.dfm}
end.
Besides the frames on the main form, I have some other elements. And if you scroll, the frames are smaller than the form. I made a screenshot, look, please. Red is a frame. And gray is a form. Why the form sticks out from under the frame? How to make it (frame) completely overlap the form? And if the information does not fit on the frame, the form can be scrolled.

How can I use pen pressure property in delphi?

I'm use this code for get pressure property but does not work. Why GetPointerPenInfo function return false?
LastError function return 87 (incorrect parameter)
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Winapi.wmPointer, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
private
{ Private declarations }
public
{ Public declarations }
procedure PenEvent(var msg: TWMPointerUpdate); message WM_POINTERUPDATE;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
{ TForm1 }
procedure TForm1.PenEvent(var msg: TWMPointerUpdate);
var
pInfo: PPointerPenInfo;
begin
if GetPointerPenInfo(msg.pointerId, pInfo) then
Label1.Caption := inttostr(pInfo.pressure);
end;
end.
You are passing an uninitialized pointer to GetPointerPenInfo(). Try this instead:
procedure TForm1.PenEvent(var msg: TWMPointerUpdate);
var
Info: TPointerPenInfo;
begin
if not GetPointerPenInfo(msg.pointerId, #Info) then RaiseLastOSError;
Label1.Caption := IntToStr(Info.pressure);
end;

Creating a VCL form in dll Delphi

I have this code that is merely trying to create a form in a DLL. I created the DLL and the form through the RAD studio Berlin IDE. I wanted to just put up a blank form to make sure it was working, unfortunately it is crashing with an EAcess violation (or alternately, an EResNotFound exception with message "Resource TSigForm can not be found"), and I can't figure out what is missing.
DLL code:
library SigDLL;
uses
System.SysUtils, System.Classes, Windows, Vcl.Forms, Vcl.Dialogs,
SignatureForm in 'SignatureForm.pas' {SigForm1};
{$R *.res}
var
SigForm: TSigForm;
procedure PrepareSigDLL(AppHandle : HWND); stdcall;
begin
SigForm := TSigForm.Create(nil); // <--------- CRASHES HERE
end;
procedure GetSignature(Variables: PChar); stdcall;
begin
ShowMessage('GetSignature called!');
end;
procedure CloseSigDLL; stdcall;
begin
ShowMessage('CloseSigDLL called!');
end;
exports
PrepareSigDLL,
GetSignature,
CloseSigDLL;
begin
end.
SigForm code:
unit SignatureForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
type
TSigForm = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
SigForm: TSigForm;
implementation
{$R *.dfm}
end.
Generic Host app for DLL:
unit SigDllHost;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
procedure PrepareSigDLL(handle: HWND); stdcall; external 'SigDll.dll';
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
PrepareSigDLL(Self.Handle);
end;
end.

How to instantiate different frame types?

I'm here again with frames.
I've this main form:
It's only a simple form created in order to understand the use of frames.
With the two buttons on the top of the form I would like to open this two frames:
Frame1
and Frame2
here is the code the simple code of the first frame:
unit AppFrame1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls;
type
TFrame1 = class(TFrame)
lblFrame1: TLabel;
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
{$R *.dfm}
end.
and here is the code of the second frame:
unit AppFrame2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls;
type
TFrame2 = class(TFrame)
lblFrame2: TLabel;
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
{$R *.dfm}
end.
So nothing special in the two frames.
in order to open the frames from the main form I've created an interface like this:
unit FramesManager;
interface
uses
Vcl.Forms, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Controls;
type
TFrameClass = class(TFrame)
end;
IFrameManager = interface
['{A00E0D1B-3438-4DC4-9794-702E8302B567}']
procedure CreateGenericFrame(AParentPanel: TPanel; AFrameClass: TFrameClass);
procedure DestroyGenericFrame();
end;
TFrameManager = class(TInterfacedObject, IFrameManager)
private
FGenericFrame: TFrameClass;
procedure CreateGenericFrame(AParentPanel: TPanel; AFrameClass: TFrameClass);
procedure DestroyGenericFrame();
public
property Frame: TFrameClass read FGenericFrame write FGenericFrame;
end;
implementation
{ TFrameManagement }
procedure TFrameManager.CreateGenericFrame(AParentPanel: TPanel;
AFrameClass: TFrameClass);
begin
FGenericFrame := AFrameClass.Create(AParentPanel);
FGenericFrame.Parent := AParentPanel;
FGenericFrame.Align := alClient;
end;
procedure TFrameManager.DestroyGenericFrame;
begin
FGenericFrame.Free;
end;
end.
At this point my intension is to use the interface for create the two frames but I can't realize how to reach this task.
My main form code is this:
unit Main;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.ExtCtrls, FramesManager, Vcl.StdCtrls, AppFrame1, AppFrame2;
type
TfrmMain = class(TForm)
pnlCommands: TPanel;
pnlFrames: TPanel;
btnCrtFrame1: TButton;
btnCrtFrame2: TButton;
procedure FormCreate(Sender: TObject);
procedure btnCrtFrame1Click(Sender: TObject);
procedure btnCrtFrame2Click(Sender: TObject);
private
FFrame: IFrameManager;
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
procedure TfrmMain.FormCreate(Sender: TObject);
begin
FFrame := TFrameManager.Create;
end;
procedure TfrmMain.btnCrtFrame1Click(Sender: TObject);
begin
FFrame.CreateGenericFrame(pnlFrames, TFrame1);
end;
procedure TfrmMain.btnCrtFrame2Click(Sender: TObject);
begin
FFrame.CreateGenericFrame(pnlFrames, TFrame2);
end;
end.
When I try co compile the project I receive this errors:
[dcc32 Error] Main.pas(41): E2010 Incompatible types: 'TFrameClass' and 'class of TFrame1'
[dcc32 Error] Main.pas(46): E2010 Incompatible types: 'TFrameClass' and 'class of TFrame2'
So I would like to understand how to create the two frames from the main.
How can I assign the right object type to the TFrameClass?
I've tought about generics, but I have not idea on how to implement this kind of interface in order to open a "generic" frame that can be created form the main when the use choose to open it.
I hope I have explained clearly my problem, but I know that it may seem complicate to understand.
type
TFrameClass = class(TFrame)
end;
Your TFrameClass declaration is wrong. Right now it is declared as a descendant of TFrame which is just another class.
What you need is a class reference:
type
TFrameClass = class of TFrame;
Because both TFrame1 and TFrame2 descend from TFrame, both can be put into a TFrameClass variable.
But I am pretty sure this TFrameClass already exists somewhere in the VCL in which case you do not have to redeclare this type.
Subsequently, the type of FGenericFrame private field needs to become TFrame instead of TFrameClass.
(Also, this has nothing to do with Generics.)

Delphi generic frame

I'm still here with a questione about Delphi frames.
I would like to create an application that use various type of frames in order to manage different database tables, so trying to understand how to do this kind of task I've create a simple Delphi Form:
unit main;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls, Vcl.ExtCtrls, FramesManagement;
type
TfrmMain = class(TForm)
pnlCommands: TPanel;
pnlFrames: TPanel;
btnFrame1: TButton;
btnFrame2: TButton;
procedure FormCreate(Sender: TObject);
procedure btnFrame1Click(Sender: TObject);
procedure btnFrame2Click(Sender: TObject);
private
FFrame: IFrameManagement;
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
uses Frame1, Frame2;
procedure TfrmMain.FormCreate(Sender: TObject);
begin
FFrame := TFramemanagement.Create;
end;
procedure TfrmMain.btnFrame1Click(Sender: TObject);
begin
FFrame.CreateGenericFrame(pnlFrames, TFrame(Frame1.TFra1));
end;
procedure TfrmMain.btnFrame2Click(Sender: TObject);
begin
FFrame.CreateGenericFrame(pnlFrames, TFrame(Frame2.TFra2));
end;
end.
This form make use of an interface declared as following:
unit FramesManagement;
interface
uses
Vcl.Forms, Vcl.StdCtrls, Vcl.ExtCtrls, Frame1, Frame2;
type
IFrameManagement = interface
['{A00E0D1B-3438-4DC4-9794-702E8302B567}']
procedure CreateGenericFrame(ParentPanel: TPanel; FrameName: TFrame);
end;
TFrameManagement = class(TInterfacedObject, IFrameManagement)
private
genericFrame: TFrame;
procedure CreateGenericFrame(ParentPanel: TPanel; FrameName: TFrame);
end;
implementation
procedure TFrameManagement.CreateGenericFrame(ParentPanel: TPanel;
FrameName: TFrame);
begin
genericFrame := FrameName.Create(ParentPanel);
genericFrame.Parent := ParentPanel;
end;
And here there are the two frames.
Frame 1:
unit Frame1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls;
type
TFra1 = class(TFrame)
txtFrame1: TStaticText;
txtFrameType: TStaticText;
lblFrameType: TLabel;
private
public
end;
implementation
{$R *.dfm}
end.
and Frame 2:
unit Frame2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls;
type
TFra2 = class(TFrame)
txtFrame2: TStaticText;
txtFrameType: TStaticText;
lblFrameType: TLabel;
private
public
end;
implementation
{$R *.dfm}
end.
This is all the code, but When I run the application and I try to create the first or the second frame i receive an error like this:
I've thought the solution may be the use of generics but I don't know how to use them. Is my thought right or there is another way to reache this gol?
Can Anyone help me?
procedure TFrameManagement.CreateGenericFrame(ParentPanel: TPanel; FrameName: TFrame);
begin
genericFrame := FrameName.Create(ParentPanel);
genericFrame.Parent := ParentPanel;
end;
Here FrameName is an instance and you are calling the constructor of that instance. You are not creating a new instance as you intend to do.
You need to use meta classes.
type
TFrameClass = class of TFrame;
procedure TFrameManagement.CreateGenericFrame(ParentPanel: TPanel; FrameClass: TFrameClass);
begin
genericFrame := FrameClass.Create(ParentPanel);
genericFrame.Parent := ParentPanel;
end;
You can call this like so:
FFrame.CreateGenericFrame(pnlFrames, Frame2.TFra2);

Resources