Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Hinstance of package. Load resource in package

311 views
Skip to first unread message

Ronaldo Rezende

unread,
May 5, 2003, 9:25:20 AM5/5/03
to
I have created a component that has an icon. I have a resource that has
the icon. This line look for the resource in the HInstance of the
application, but the resource is compiled in the library of the package,
not in the application. So, It does't find the Resource. What I must do
to solve it? If I include the resource in my application, it work ok,
but I don't want this.
Glyph.LoadFromResourceName(HInstance,'TSBFECHAR');


constructor TSbFechar.Create(AOwner: TComponent);
begin
inherited;
Width := 60;
Height := 38;
Hint := 'Sair|Finaliza e retorna ao formulário anterior.';
Caption := 'Fechar';
Flat := True;
Glyph.LoadFromResourceName(HInstance,'TSBFECHAR');
Layout := blGlyphTop;
Spacing := -3;
OnClick := SbFecharClick;
end;


TOndrej

unread,
May 5, 2003, 9:49:30 AM5/5/03
to

Instead of HInstance, you can use, for example,
FindHInstance(Self.ClassType)

HTH
TOndrej


Ronaldo Rezende

unread,
May 5, 2003, 1:20:53 PM5/5/03
to
What I must do?

HInstance =
FindHInstance(Self.ClassType) =
FindClassHInstance(TSbFechar)

I have a component in a design time only package datamodule.dpk
My resource is in datamodule.dpk
I'm needing the HInstance of the package where my resource is.

TOndrej

unread,
May 5, 2003, 5:56:26 PM5/5/03
to
> What I must do?
>
> HInstance =
> FindHInstance(Self.ClassType) =
> FindClassHInstance(TSbFechar)
>
> I have a component in a design time only package datamodule.dpk
> My resource is in datamodule.dpk
> I'm needing the HInstance of the package where my resource is.

If you need the resource at runtime then you should link it with the runtime
package, not designtime.

HTH
TOndrej

Ronaldo Rezende

unread,
May 5, 2003, 7:47:38 PM5/5/03
to
Can I change my design time package to run time package without have any
problem with my component? If I do this, I must include the package library
in the distribuited files?

TOndrej <ton...@t-online.de> escreveu nas notícias de
mensagem:3eb6...@newsgroups.borland.com...

Rob Kennedy

unread,
May 5, 2003, 9:27:55 PM5/5/03
to
Ronaldo Rezende wrote:
> Can I change my design time package to run time package without have any
> problem with my component?

No. You need to have two packages: one design-time and one run-time.

Your run-time package should include your component code and your
resource files. In particular, your run-time package should *not* use
the DsgnIntf or DesignIntf units.

Your design-time package should have your run-time package in its
"requires" clause. The design-time package is what should contain the
Register procedure and the calls to RegisterComponents.

> If I do this, I must include the package library
> in the distribuited files?

If your application is compiled with run-time packages turned on, then
you must distribute the run-time package with your program. If you are
distributing your component to other developers, then you must also
include the design-time package and the DCUs or the source files.

--
Rob

Ronaldo Rezende Vilela Luiz

unread,
May 6, 2003, 6:54:03 AM5/6/03
to
My package has only two TSpeedButon with a icon and a TClientDataSet
derived.
I must put an package inside another package?

"Rob Kennedy" <rken...@cs.wisc.edu> escreveu na mensagem
news:3eb70fb4$1...@newsgroups.borland.com...

Rob Kennedy

unread,
May 6, 2003, 12:26:57 PM5/6/03
to
Ronaldo Rezende Vilela Luiz wrote:
> My package has only two TSpeedButon with a icon and a TClientDataSet
> derived.
> I must put an package inside another package?

Not inside. Your design-time package will only contain code to register
your run-time package with the IDE. Your run-time package will contain
your custom component. You have to do it this way because it is against
your license agreement for you to distribute the registration code,
which is what you would have to do if the registration code were in your
run-time package. The more recent versions of Delphi actually enforce
that part of the license by making it impossible to compile your
program; you won't have all the necessary units to include the
registration code.

The concept that one package uses another is not alien. Both your
run-time package and your design-time package require the VCL packages,
for instance.

--
Rob


Ronaldo Rezende

unread,
May 7, 2003, 8:15:18 AM5/7/03
to
I alredy do this, but my problem wasn't solve. I have created a run-time
package with my component's unit inside it. And I have created a
design-time package with the register procedure. In the unit of register
procedure, I put the units of components in the uses clause.

Rob Kennedy

unread,
May 7, 2003, 2:18:04 PM5/7/03
to
Ronaldo Rezende wrote:
> I alredy do this, but my problem wasn't solve. I have created a run-time
> package with my component's unit inside it. And I have created a
> design-time package with the register procedure. In the unit of register
> procedure, I put the units of components in the uses clause.

The first thing to check is that you are spelling it "Register" with a
capital R. That procedure name is case-sensitive; the IDE won't register
anything if it cannot find that procedure name.

Your registration unit should look like this:

unit RegMyComponents;

interface

procedure Register;

implementation

uses DsgnIntf {or DesignIntf}, MyComponentUnit;

procedure Regsiter;
begin
RegisterComponents('Component Palette Title', [TMyComponent]);
end;

end.

If your problem still isn't solved, then please post what code you have
and tell exactly what errors you are receiving.

--
Rob


Ronaldo Rezende Vilela Luiz

unread,
May 7, 2003, 3:11:40 PM5/7/03
to
My problem is: I have created two buttons derived from TSpeedButton with
a predefined icon. I created a resource file with the icons.

1 - When I run my program, the function Glyph.LoadFromResourceName
doesn't localize the icon. The FindHInstance method has the same values
of HInstance. To resolve this, I created a design time package to
register my components. And put my components in a run time package. The
problem wasn't resolve after this. The FindHInstance still has the same
value of HInstance. So, the LoadFromResourceName doens't find my icon,
because my icon is in the resource in my run-time package.

2 - After I installed the design time package, I close the kylix, and
when I open it I receive a message error:

Can't load package /Projeto/Matrix A/Components/bpldatamodules.so.
bplRTDataModules.so: cannot open shared object file: Arquivo ou
diretório não encontrado.
Do you want to attempt to load this package the next time a project is
loaded?


my register unit
---
unit UDataModulesRegister;

interface

uses DesignEditors, DesignIntf, UMDtmBaseServidorAbstract, UMDtmBaseCliente,
UMFrmBaseCds, UMFrmPesquisa, Classes, QSbAbrir, QSbFechar,
QSbPesquisa;

procedure Register;

implementation

procedure Register;
begin
RegisterCustomModule(TMDtmBaseServidorAbstract,TCustomModule);
RegisterCustomModule(TMDtmBaseCliente,TCustomModule);
RegisterCustomModule(TMFrmBaseCds,TCustomModule);
RegisterComponents('Botões', [TSbAbrir,TSbFechar,TSbPesquisa]);
end;
end.
-------

One of my components:
-----
unit QSbPesquisa;

interface

uses
SysUtils, Classes, QControls, QButtons;

type
TSbPesquisa = class(TSpeedButton)
private
protected
public
constructor Create(AOwner: TComponent); override;
published
end;

implementation

constructor TSbPesquisa.Create(AOwner: TComponent);
begin
inherited;
Width := 25;
Height := 23;
Hint := 'Pesquisar';
Flat := True;
Glyph.LoadFromResourceName(FindHInstance(Self.ClassType),'TSBPESQUISA');
end;

end.
-------

Rob Kennedy

unread,
May 7, 2003, 3:22:05 PM5/7/03
to
Ronaldo Rezende Vilela Luiz wrote:
> 2 - After I installed the design time package, I close the kylix, and
> when I open it I receive a message error:
>
> Can't load package /Projeto/Matrix A/Components/bpldatamodules.so.
> bplRTDataModules.so: cannot open shared object file: Arquivo ou
> diretório não encontrado.
> Do you want to attempt to load this package the next time a project is
> loaded?

Well, the first thing to check is that the files actually do exist in
the directories Kylix is looking in. Could Linux's case-sensitive file
names have anything to do with it?

--
Rob


Ronaldo Rezende Vilela Luiz

unread,
May 7, 2003, 3:30:24 PM5/7/03
to
The names are correctly and the file exists.


"Rob Kennedy" <rken...@cs.wisc.edu> escreveu na mensagem

news:3eb95cf8$1...@newsgroups.borland.com...

Ronaldo Rezende Vilela Luiz

unread,
May 7, 2003, 3:44:26 PM5/7/03
to
There is a strange think.
It's trying to load bpldatamodules.so.bplRTDataModules.so
There is on file named bpldatamodules.so and other bplRTDataModules.so
In the message error, the name of file is:

Can't load package /Projeto/Matrix A/Components/bpldatamodules.so.
bplRTDataModules.so:

Is possible that kylix is looking for 1 file named
"bpldatamodules.so.bplRTDataModules.so" ?

TOndrej

unread,
May 8, 2003, 9:11:28 AM5/8/03
to
> My problem is: I have created two buttons derived from TSpeedButton
> with a predefined icon. I created a resource file with the icons.
>
> 1 - When I run my program, the function Glyph.LoadFromResourceName
> doesn't localize the icon. The FindHInstance method has the same
> values of HInstance.

I presume that by 'localize' you mean 'locate'.
Are you talking about FindHInstance _function_ from System unit?
That's not a method, it's a function and it returns a handle of a
module based on the given address. Therefore,
FindHInstance(Pointer(TMyClass)) or (FindHInstance(Self.ClassType))
will return the handle of the module which contains the given class:

- If you're not using runtime packages (project options) then all
classes used throughout the project are compiled into the target
executable, so the returned value will always be equal to HInstance.
- If you're using runtime packages (project options) but the specific
runtime package is not included in the project options list of runtime
packages then any classes from that package are linked directly with
your executable, so the returned value will be equal to HInstance.
- If you're using runtime packages (project options) and the runtime
package is included in the project options list of runtime packages
then the returned value is the handle of the runtime package which
contains the class.

> To resolve this, I created a design time package to
> register my components. And put my components in a run time package.

By creating a design package and registering your components in it,
all you do is make the components available to the IDE, nothing more.

> The problem wasn't resolve after this. The FindHInstance still has
> the same value of HInstance.

You're probably not using the runtime package where your component
class (and the resource) is. Either you're not using runtime packages
at all (so the executable contains all used classes), or you're not
using the specific package because it's not included in the project
options list of runtime packages.

> So, the LoadFromResourceName doens't find my icon,
> because my icon is in the resource in my run-time package.

In either case, all you need to do is make sure that your resource
gets linked into the same module as your class. The easiest way to do
this is put your {$R ...} directive directly into the unit where your
class is implemented.
Then your class and your resource will always be linked into the same
module, whether it's the main executable or a runtime package.

> 2 - After I installed the design time package, I close the kylix,
and
> when I open it I receive a message error:

Creating a design package has no effect on runtime.
If you're having problems at design time, make sure your design
package is created properly:
First create the runtime package and make sure it compiles and is
usable at runtime (perhaps write a test project).
Then create the design package, requiring the runtime package (in its
'requires' clause) and add a new unit with your IDE registration code.

HTH
TOndrej

0 new messages