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;
Instead of HInstance, you can use, for example,
FindHInstance(Self.ClassType)
HTH
TOndrej
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
TOndrej <ton...@t-online.de> escreveu nas notícias de
mensagem:3eb6...@newsgroups.borland.com...
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
"Rob Kennedy" <rken...@cs.wisc.edu> escreveu na mensagem
news:3eb70fb4$1...@newsgroups.borland.com...
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
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
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.
-------
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
"Rob Kennedy" <rken...@cs.wisc.edu> escreveu na mensagem
news:3eb95cf8$1...@newsgroups.borland.com...
Is possible that kylix is looking for 1 file named
"bpldatamodules.so.bplRTDataModules.so" ?
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