Re: [fpc-pascal] WinCE multithreading

2011-09-14 Thread Fabio Luis Girardi
I'm debugging and I have doubt: I'm using records and pointers to
records. On WinCE wiki, the use of unaligned only shows with pointers
to integer. And with recods, I must do

unalinged(myrec^).member

or

unalinged(myrec^.member)


???


The best regards,

Fabio Luis Girardi
PascalSCADA Project
http://sourceforge.net/projects/pascalscada
http://www.pascalscada.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] WinCE multithreading

2011-09-14 Thread Jonas Maebe

On 14 Sep 2011, at 19:16, Fabio Luis Girardi wrote:

 I'm debugging and I have doubt: I'm using records and pointers to
 records. On WinCE wiki, the use of unaligned only shows with pointers
 to integer. And with recods, I must do
 
 unalinged(myrec^).member
 
 or
 
 unalinged(myrec^.member)


If the pointer itself is stored at a potentially unaligned address, you need 
unaligned(myrec). If the record the pointer points to is stored at a 
potentially unaligned address, you need unaligned(myrec^.member). If both are 
the case, you need unaligned(unaligned(myrec)^.member)

I'm fairly certain that unaligned(myrec^).member won't do anything.


Jonas___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] WinCE multithreading

2011-09-14 Thread Felipe Monteiro de Carvalho
But is the unaligned still required? I remember that unaligned access
was sure crash in WinCE many years ago, but I vaguely remember someone
mentioned that FPC had improved it's support for the compiler figuring
out on it's own when something is unaligned. While doing Android
development for example, I haven't yet had a single crash due to
unaligned access ... and I made no use of this keyword so far.

-- 
Felipe Monteiro de Carvalho
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Interface, _AddRef, _Release, etc.

2011-09-14 Thread Marcos Douglas
Hi,

A class (TFoo) implements an interface (IFoo), but my class has more
methods and properties (in the eg below just one more method) that I
need use.

Another object has a property of IFoo type.
So, I created a Foo and assigns my object property.

From this moment I can not longer release my Foo object, because the refcount.

See (attention in the comments below):

program p1;

{$ifdef FPC}
  {$mode objfpc}{$H+}
{$else}
  {$apptype console}
{$endif}

uses  heaptrc,  Classes,  SysUtils;

type
  IFoo = interface
['{F71A4131-E0A5-48CB-B563-7BBB079D1085}']
function GetInfo: string;
  end;

  TFoo = class(TInterfacedObject, IFoo)
  private
FInfo: string;
  protected
  public
function GetInfo: string;
procedure SetInfo(const AValue: string);
  end;

function TFoo.GetInfo: string;
begin
  Result := FInfo;
end;

procedure TFoo.SetInfo(const AValue: string);
begin
  FInfo := AValue;
end;

type
  TObj = class(TObject)
  public
Foo: IFoo;
  end;

procedure Run;
var
  f: TFoo;  //  type is class, not interface
  o: TObj;
begin
  f := TFoo.Create;
  f.SetInfo('foo');
  o := TObj.Create;
  o.Foo := f;
  writeln(o.Foo.GetInfo);
  o.Free;
//  f.Free; //  I can't use it because it already was freed
end;

begin
  Run;
  writeln('Done');
end.

BUT, if I create my TFoo without refcount should works, right?
So, I change my class:

  TFoo = class(TObject, IFoo)
  private
FInfo: string;
  protected
function QueryInterface(const iid : tguid;out obj) : longint;stdcall;
function _AddRef : longint;stdcall;
function _Release : longint;stdcall;
  public
function GetInfo: string;
procedure SetInfo(const AValue: string);
  end;

function TFoo.QueryInterface(const iid: TGuid; out obj): longint; stdcall;
begin
  if GetInterface(iid,obj) then
Result := S_OK
  else
Result:=longint(E_NOINTERFACE);
end;

function TFoo._AddRef: longint; stdcall;
begin
  Result := -1;
end;

function TFoo._Release: longint; stdcall;
begin
  Result := -1;
end;

... but, does not work. In Delphi 7 yes, but no in FPC.

See this http://bugs.freepascal.org/view.php?id=15526

Do you think this is right?

Marcos Douglas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal