Board index » delphi » help: accessing Classes via Property

help: accessing Classes via Property

This is probably a simple problem but has been causing me grief for
awhile now.  I am using a seperate form/unit to do some processing for
a class and using the PROPERTY command, I have tried to simply show
the way I set it up below.  The problem is that any changes I make to
the private var 'nowset' elsewhere in the form, does not get passed
back to the parent form .  ????  I also tried to set a global var in
the main form, but it doesn't seem to have scope in the unit "b"?

If anyone could help me I would be very appreciated!  If more detailed
code is required please email me at "rough...@mindspring.com".  PLEASE
HELP ME!!

---seperate .pas file "a"---
myclass=class
...
end;

---main form---
uses a,b;

var
  v: myclass;

begin
  b.set:= v;
  b.showmodal;
  v:=b.set;
end;

--seperate unit/form "b"---
uses a;

thisform=class
private
  nowset: myclass;
public
  property set read myclass write myclass;
end;

 

Re:help: accessing Classes via Property


Quote
Ian Roughley wrote:

> This is probably a simple problem but has been causing me grief for
> awhile now.  I am using a seperate form/unit to do some processing for
> a class and using the PROPERTY command, I have tried to simply show
> the way I set it up below.  The problem is that any changes I make to
> the private var 'nowset' elsewhere in the form, does not get passed
> back to the parent form .  ????  I also tried to set a global var in
> the main form, but it doesn't seem to have scope in the unit "b"?

> If anyone could help me I would be very appreciated!  If more detailed
> code is required please email me at "rough...@mindspring.com".  PLEASE
> HELP ME!!

> ---seperate .pas file "a"---
> myclass=class
> ...
> end;

> ---main form---
> uses a,b;

> var
>   v: myclass;

> begin
>   b.set:= v;
>   b.showmodal;
>   v:=b.set;
> end;

> --seperate unit/form "b"---
> uses a;

> thisform=class
> private
>   nowset: myclass;
> public
>   property set read myclass write myclass;
> end;

        I don't know whether more detailed code is required but
more accurate code certainly is. From the code you post it
looks like you're trying to showmodal a UNIT. That can't
be what you're actually doing, but if we can't see what you're
actually doing it's hard to say what the problem is.

--
David Ullrich

?his ?s ?avid ?llrich's ?ig ?ile
(Someone undeleted it for me...)

Re:help: accessing Classes via Property


Okay,

I might have forgotten to add that it was a class inherited from
form....

Quote

>    I don't know whether more detailed code is required but
>more accurate code certainly is. From the code you post it
>looks like you're trying to showmodal a UNIT. That can't
>be what you're actually doing, but if we can't see what you're
>actually doing it's hard to say what the problem is.

>--
>David Ullrich

It compiles OK, but variables in the spriteLibrary class aren't passed
forward/backwards properly.  Thanx in advance, and I hope you can
help!

Here is the ACTUAL code segments....

--------------------------------------------------------------------------------
unit sprite3dlibrary;

interface

uses
  ...

type

TBitmapStorage = array[0..BitmapX,0..BitmapY] of TColor;

PBitmapPixellocRec = ^BitmapPixellocRec;
BitmapPixellocRec = record
  exists: boolean;
  loc: TBitmapStorage;
end;

PspriteInstRec = ^spriteInstRec;
spriteInstRec = record
  numFrames: Integer;
  sprite3D: array[0..7,0..maxFrames-1] of PBitmapPixellocRec;
  timeDep: Boolean;
  timeInt:Integer;
  spritename: string;
end;

{ the classes I need for displaying the sprites }

TspriteLibrary = class
private
  ...
public
  spriteImages: array[1..maxSprites] of PspriteInstRec;
  .....
end;

implementation
  ....
-------------------------------------------------------------
unit dispSprite;

interface

uses
 ...

type
  TShowSprite = class(TForm)
    ....
  private
    anyloaded: boolean;
    CrntLib: TspriteLibrary;
  public
    property SetParentLib: TspriteLibrary read CrntLib write CrntLib;
  end;

var
  ShowSprite: TShowSprite;
  newSprite: PspriteInstRec;  { information about the sprite library }

implementation
  ....
----------------------------------------------------------

Then in the main form

var
  LibraryForm: TLibraryForm;
  maxXsprite,
  maxYsprite: integer;
  workingLib: TspriteLibrary;

Implementation
....

procedure TLibraryForm.compileLibClick(Sender: TObject);
begin
  ShowSprite.SetParentLib:=workingLib;
  ShowSprite.ShowModal;
  workingLib:= ShowSprite.SetParentLib;
  UpdateInfo;
end;

Re:help: accessing Classes via Property


Quote
Ian Roughley wrote:

[...]

Quote
> It compiles OK, but variables in the spriteLibrary class aren't passed
> forward/backwards properly.  Thanx in advance, and I hope you can
> help!

> Here is the ACTUAL code segments....

> --------------------------------------------------------------------------------
> unit sprite3dlibrary;

> interface

> uses
>   ...

> type

> TBitmapStorage = array[0..BitmapX,0..BitmapY] of TColor;

> PBitmapPixellocRec = ^BitmapPixellocRec;
> BitmapPixellocRec = record
>   exists: boolean;
>   loc: TBitmapStorage;
> end;

> PspriteInstRec = ^spriteInstRec;
> spriteInstRec = record
>   numFrames: Integer;
>   sprite3D: array[0..7,0..maxFrames-1] of PBitmapPixellocRec;
>   timeDep: Boolean;
>   timeInt:Integer;
>   spritename: string;
> end;

> { the classes I need for displaying the sprites }

> TspriteLibrary = class
> private
>   ...
> public
>   spriteImages: array[1..maxSprites] of PspriteInstRec;
>   .....
> end;

> implementation
>   ....
> -------------------------------------------------------------
> unit dispSprite;

> interface

> uses
>  ...

> type
>   TShowSprite = class(TForm)
>     ....
>   private
>     anyloaded: boolean;
>     CrntLib: TspriteLibrary;
>   public
>     property SetParentLib: TspriteLibrary read CrntLib write CrntLib;
>   end;

> var
>   ShowSprite: TShowSprite;
>   newSprite: PspriteInstRec;  { information about the sprite library }

> implementation
>   ....
> ----------------------------------------------------------

> Then in the main form

> var
>   LibraryForm: TLibraryForm;
>   maxXsprite,
>   maxYsprite: integer;
>   workingLib: TspriteLibrary;

> Implementation
> ....

> procedure TLibraryForm.compileLibClick(Sender: TObject);
> begin
>   ShowSprite.SetParentLib:=workingLib;
>   ShowSprite.ShowModal;
>   workingLib:= ShowSprite.SetParentLib;
>   UpdateInfo;
> end;

        I can't see anything wrong with this just offhand (which
certainly doesn't prove there's not 17 obvious blunders staring
me in the face).
        When you say the variables are not getting passed back
and forth properly presumably you're referring to the last
bit (compileLibClick) (??) Is workingLib getting created
somewhere? How do you know that the value of workingLib is
wrong after the compileLibClick? What is this UpdateInfo
thing? >>> Are you _certain_ that ShowSprite is actually doing
what it's supposed to do with its CrntLib? (Like, if you
make a standalone TSpriteLibrary instead of a ShowModal
one it does the right thing?)

--
David Ullrich

?his ?s ?avid ?llrich's ?ig ?ile
(Someone undeleted it for me...)

Other Threads