Small blind zone in Delphi development

zhaozj2021-02-16  48

Type variable assignment

First, look at the following piece of code run to see what procedure TForm1.Button1Click (Sender: TObject); var FormImage: TBitmap; begin FormImage: = TBitmap.Create; FormImage: = GetFormImage; try formImage.SaveToFile ( 'c: / a. BMP '); Finally formimage.free; end; end;

You can analyze if there is a problem with the code above. Although there will be no errors when you debug, the facts have a big problem, because

GetformImage returned itself is a Tbitmap type object and uses VCL's create method to create an instance, we cannot use ": =" between instances; you can only use two ways to operate

method one:

Procedure TForm1.Button1Click (Sender: Tobject); Var form: Tbitmap; // Declare a type of variable begin // formimage: = tbitmap.create; // This sentence should not be formigure: = getformImage; // Tmorm method Assign the value to the variable, which is equivalent to using the Create method, you can use directly, try formimage.Savetofile ('c: /a.bmp'); Finally Formimage.Free; end; end; method 2:

Using Assign, you must construct an instance using the CREATE method, because when using ASSIGN to operate the object, you can copy the properties of the source instance into the target instance, but if the type variable of the operating large structure is not high.

Following procedure TForm1.Button2Click (Sender: TObject); var FormImage: TBitmap; begin FormImage: = TbitMap.Create; FormImage.Assign (GetFormImage); try formImage.SaveToFile ( 'c: /a.bmp'); finally FormImage.Free ; End;

Thanks for the previous engineering manager, China BCB Forum Bamboo Lewolf Big Brother ^ _ ^

QQ: 53997882

转载请注明原文地址:https://www.9cbs.com/read-26237.html

New Post(0)