Pregunta

I have downloaded opensource delphi twain component (TDelphiTwain). The interesting thing is, that when placed and saved on the form it creates bad dfm entry for itself.

  object DelphiTwain: TDelphiTwain
    OnSourceDisable = DelphiTwainSourceDisable
    OnSourceSetupFileXfer = DelphiTwainSourceSetupFileXfer
    TransferMode = ttmMemory
    SourceCount = 0
    Info.MajorVersion = 1
    Info.MinorVersion = 0
    Info.Language = tlDanish
    Info.CountryCode = 1
    Info.Groups = [tgControl, tgImage, tgAudio, MinorVersion]
    Info.VersionInfo = 'Application name'
    Info.Manufacturer = 'Application manufacturer'
    Info.ProductFamily = 'App product family'
    Info.ProductName = 'App product name'
    LibraryLoaded = False
    SourceManagerLoaded = False
    Left = 520
    Top = 136
  end

The problem is with the line:

   Info.Groups = [tgControl, tgImage, tgAudio, MinorVersion]

There are only three possible elements:

tgControl, tgImage and tgAudio

It adds MinorVersion everytime I Save the form. When the app is run I get the error that there is invalid property for Info.Groups. When i rmeove the bad part manually and without leaving dfm file the app starts ok.

I looked in the internet and there was one inquire regarding these strange issue, unfortunately it hasn't been resolved.

I think that there is some sort of memory corruption. In the post in teh internet, strange signs were displayed ...

Has anyone worked with that component or could give me some hint how this could be fixed?

¿Fue útil?

Solución

The error seems to be in TTwainIdentity.GetGroups where result is not initialized. You can try to change the code by replacing

Include(Result, tgControl);

with

Result := [tgControl]; 

You have to recompile the package to make this change work inside the IDE.

Otros consejos

I don't know the component, but I think the problem lies in the TTwainIdentity.GetGroups method. It starts like this:

begin
  Include(Result, tgControl);

This means that it assumes that Result is initialized to an empty set. However, Result may contain garbage, and not necessarily an empty set. Change this method to look like this:

function TTwainIdentity.GetGroups(): TTwainGroups;
  {Convert from Structure.SupportedGroups to TTwainGroups}
begin
  Result := [tgControl];
  if DG_IMAGE AND Structure.SupportedGroups <> 0 then
    Include(Result, tgImage);
  if DG_AUDIO AND Structure.SupportedGroups <> 0 then
    Include(Result, tgAudio);
end;

Some result types will not throw a compiler warning about not being initialized, but that doesn't mean they are empty. Same goes, for instance, for strings. See also: http://qc.embarcadero.com/wc/qcmain.aspx?d=894

But still, it is odd that this happens. Apparently, Delphi tries to find the name of the given item in the set and accidentally finds the name of another property. It seems to me that quite some checks in writing the dfm are missing if this happens. :)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top