Delphi XE7中Android上设置表单属性时未分配句柄

Delphi XE7中Android上设置表单属性时未分配句柄,android,forms,delphi,firemonkey,delphi-xe7,Android,Forms,Delphi,Firemonkey,Delphi Xe7,打开我在XE7中创建的新表单时遇到问题。我在Samsung Galaxt tab2上打开表单没有问题,但是当我想在Sony Xperia ZR上打开表单时,我会得到一个句柄not Allocated异常 代码如下: procedure TfrmNocoreDKS.actOpenDocumentExecute(Sender: TObject); var frmDKSDocument: TfrmDKSDocument; begin frmDKSDocument := TfrmDKSDocum

打开我在XE7中创建的新表单时遇到问题。我在Samsung Galaxt tab2上打开表单没有问题,但是当我想在Sony Xperia ZR上打开表单时,我会得到一个句柄not Allocated异常

代码如下:

procedure TfrmNocoreDKS.actOpenDocumentExecute(Sender: TObject);
var
  frmDKSDocument: TfrmDKSDocument;
begin
  frmDKSDocument := TfrmDKSDocument.Create(nil);
  frmDKSDocument.ScaleBy := fScaleBy; 
  frmDKSDocument.UseAantal := fUseAantal;
  frmDKSDocument.DocumentId := TButton(Sender).Tag;
  frmDKSDocument.LoadDocument;
  frmDKSDocument.SetDocumentStatus := SetDocumentStatus;
  frmDKSDocument.Allowresize := True;
  frmDKSDocument.Show;
  frmDKSDocument.FillSigns;
end;
TfrmDksDocument = class(TForm)
private
  fScaleBy:Single;
public
  property ScaleBy:Single read fScaleBy write SetScaleBy;

procedure TfrmDksDocument.SetScaleBy(const Value: Single);
begin
  fScaleBy := Value;
  sgnController.ScaleBy := fScaleBy; //sgnController is a Custom Image component
  sgnController.setbitmap; //Here I get the exception
  sgnCustomer.ScaleBy := fScaleBy; //sgnCustomeris a Custom Image component
  sgnCustomer.setbitmap;
end;
procedure TisImage64.SetBitmap;
begin
  {$IFDEF WIN32}
  if not fBitmapCreated then
  Begin
    self.Bitmap := TBitMap.Create;
    self.Bitmap.SetSize(integer(trunc(Self.Size.Width)), integer(trunc(Self.Size.Height)));
    fBitmapCreated := True;
    self.clear;
  End;
  {$ENDIF}
  {$IFDEF ANDROID}
    self.Bitmap := MultiResBitMap.Add.Bitmap; //.Add.Bitmap;
    self.Bitmap.SetSize(integer(trunc(Self.Size.Width*fScaleBy)), integer(trunc(Self.Size.Height*fScaleBy)));
    fBitmapCreated := True;
    self.Clear;
  {$ENDIF}
  {$IFDEF IOS}
    self.Bitmap := MultiResBitMap.Add.Bitmap; //.Add.Bitmap;
    self.Bitmap.SetSize(integer(trunc(Self.Size.Width*fScaleBy)), integer(trunc(Self.Size.Height*fScaleBy)));
    fBitmapCreated := True;
    self.Clear;
  {$ENDIF}
end;
下面的代码显示了属性和setter的偏差:

procedure TfrmNocoreDKS.actOpenDocumentExecute(Sender: TObject);
var
  frmDKSDocument: TfrmDKSDocument;
begin
  frmDKSDocument := TfrmDKSDocument.Create(nil);
  frmDKSDocument.ScaleBy := fScaleBy; 
  frmDKSDocument.UseAantal := fUseAantal;
  frmDKSDocument.DocumentId := TButton(Sender).Tag;
  frmDKSDocument.LoadDocument;
  frmDKSDocument.SetDocumentStatus := SetDocumentStatus;
  frmDKSDocument.Allowresize := True;
  frmDKSDocument.Show;
  frmDKSDocument.FillSigns;
end;
TfrmDksDocument = class(TForm)
private
  fScaleBy:Single;
public
  property ScaleBy:Single read fScaleBy write SetScaleBy;

procedure TfrmDksDocument.SetScaleBy(const Value: Single);
begin
  fScaleBy := Value;
  sgnController.ScaleBy := fScaleBy; //sgnController is a Custom Image component
  sgnController.setbitmap; //Here I get the exception
  sgnCustomer.ScaleBy := fScaleBy; //sgnCustomeris a Custom Image component
  sgnCustomer.setbitmap;
end;
procedure TisImage64.SetBitmap;
begin
  {$IFDEF WIN32}
  if not fBitmapCreated then
  Begin
    self.Bitmap := TBitMap.Create;
    self.Bitmap.SetSize(integer(trunc(Self.Size.Width)), integer(trunc(Self.Size.Height)));
    fBitmapCreated := True;
    self.clear;
  End;
  {$ENDIF}
  {$IFDEF ANDROID}
    self.Bitmap := MultiResBitMap.Add.Bitmap; //.Add.Bitmap;
    self.Bitmap.SetSize(integer(trunc(Self.Size.Width*fScaleBy)), integer(trunc(Self.Size.Height*fScaleBy)));
    fBitmapCreated := True;
    self.Clear;
  {$ENDIF}
  {$IFDEF IOS}
    self.Bitmap := MultiResBitMap.Add.Bitmap; //.Add.Bitmap;
    self.Bitmap.SetSize(integer(trunc(Self.Size.Width*fScaleBy)), integer(trunc(Self.Size.Height*fScaleBy)));
    fBitmapCreated := True;
    self.Clear;
  {$ENDIF}
end;
SetBitmap方法的代码:

procedure TfrmNocoreDKS.actOpenDocumentExecute(Sender: TObject);
var
  frmDKSDocument: TfrmDKSDocument;
begin
  frmDKSDocument := TfrmDKSDocument.Create(nil);
  frmDKSDocument.ScaleBy := fScaleBy; 
  frmDKSDocument.UseAantal := fUseAantal;
  frmDKSDocument.DocumentId := TButton(Sender).Tag;
  frmDKSDocument.LoadDocument;
  frmDKSDocument.SetDocumentStatus := SetDocumentStatus;
  frmDKSDocument.Allowresize := True;
  frmDKSDocument.Show;
  frmDKSDocument.FillSigns;
end;
TfrmDksDocument = class(TForm)
private
  fScaleBy:Single;
public
  property ScaleBy:Single read fScaleBy write SetScaleBy;

procedure TfrmDksDocument.SetScaleBy(const Value: Single);
begin
  fScaleBy := Value;
  sgnController.ScaleBy := fScaleBy; //sgnController is a Custom Image component
  sgnController.setbitmap; //Here I get the exception
  sgnCustomer.ScaleBy := fScaleBy; //sgnCustomeris a Custom Image component
  sgnCustomer.setbitmap;
end;
procedure TisImage64.SetBitmap;
begin
  {$IFDEF WIN32}
  if not fBitmapCreated then
  Begin
    self.Bitmap := TBitMap.Create;
    self.Bitmap.SetSize(integer(trunc(Self.Size.Width)), integer(trunc(Self.Size.Height)));
    fBitmapCreated := True;
    self.clear;
  End;
  {$ENDIF}
  {$IFDEF ANDROID}
    self.Bitmap := MultiResBitMap.Add.Bitmap; //.Add.Bitmap;
    self.Bitmap.SetSize(integer(trunc(Self.Size.Width*fScaleBy)), integer(trunc(Self.Size.Height*fScaleBy)));
    fBitmapCreated := True;
    self.Clear;
  {$ENDIF}
  {$IFDEF IOS}
    self.Bitmap := MultiResBitMap.Add.Bitmap; //.Add.Bitmap;
    self.Bitmap.SetSize(integer(trunc(Self.Size.Width*fScaleBy)), integer(trunc(Self.Size.Height*fScaleBy)));
    fBitmapCreated := True;
    self.Clear;
  {$ENDIF}
end;

有人知道解决方案吗?

两个图像组件的大小设置不正确

我认为这需要更多信息
.ScaleBy
是VCL表单中的一个方法,但它在FMX表单中不作为属性存在,因此您添加了它。它的声明是什么?它实际上是一个财产吗?它有二传手吗?什么是
fScaleBy
?它是一个具有返回值的方法吗?如果是,其执行情况如何?如果没有,在何处以及如何定义?您确定是该行导致了异常吗?当引发异常时,指令指针通常会向前移动-您是否仔细检查了
TfrmDKSDocument
构造函数以确保不存在异常?包括调用堆栈也会很有帮助。好的……那么setter中的哪一行引发了异常?您可以在
fScaleBy:=Value
并逐步执行
F7
,如果您还没有这样做。什么是
sgnController
sgnCustomer
?如果抛出异常,那么它们的
ScaleBy
属性是否具有setter?如果是,他们的代码是什么样子的?
setbitmap
做什么?向下搜索,直到找到导致问题的确切线路-同样,调用堆栈会立即告诉我们这一点。无效句柄使我怀疑对
的调用。setbitmap
-试图绘制到无效上下文,等等。。。不过,如果您进行一些调试并进行报告,就容易多了。很高兴成为您的橡皮鸭。;)