* * *

Recent Posts

Pages: [1] 2 3 ... 10
1
Beginners / Re: Your thoughts on best advice for cross platform graphics
« Last post by lainz on Today at 06:22:42 pm »
Ok, I will try to make an interior scene suitable for a demo room with all kind of materials.

I'm not familiar with internal render, but I will try, maybe it takes me a week or two, since I will do only on my free time.
2
General / Re: ABS truncates a Variant float ?
« Last post by Bart on Today at 06:22:09 pm »
Point is that Abs() currently throws a compile time error on that code, and it stops doing that when you introduce the variant overload.

Bart
3
Wow, you're cool, guys :) Much better than anything I can do. Some time ago I've been trying to include some models from OpenGameArt and BlendSwap in my games, but most of the time they appeared either non-game-ready (e.g. 30M+ tris) or too diverse to make a proper composition.
Unfortunately I'm not familiar with most advanced Castle Game Engine features, but if we could come up with a nice scene in blender internal render (there are some problems with exporting cycles-relative parameters with blender X3D exporter), I'll try to handle the programming part. It'll be a good exercise for me and if something will go wrong, we can always ask Michalis, the engine author, for help :)
4
General / Re: ABS truncates a Variant float ?
« Last post by Thaddy on Today at 06:05:33 pm »
Concentrate on integer vs floats.

Function ABS(V:Variant):Variant; Overload; inline;
Begin
  result := v;
  If VarIsNumeric(V) Then
    if V< 0 Then result := -v;
end;   [/code] :D

This will also allow code like this to compile:
Code: Pascal  [Select]
  1. var
  2.   S : String;
  3.  
  4. begin
  5.   S:='My very nice string';
  6.   S:=Abs(S);
  7. end;
  8.  

That would be bad.

Bart
That's why you need to initialize result to varnull as per my example here http://forum.lazarus.freepascal.org/index.php/topic,40223.msg277657.html#msg277657 .
That gets handled correctly because it throws a descriptive runtime error in all cases.

In general the bug is described only half-way and it should be fixed. And it can be fixed. Nothing to do with rt vs ct.
5
General / Re: ABS truncates a Variant float ?
« Last post by jamie on Today at 06:04:51 pm »
My point was to have at least a compiler WARNING so the coder can type case it for local overloads!

 Or:
   Do as the 64bit port does when it decides to change the type (MyWORD+1) to a integer, if two or more
overloads are present, It can't decide which one to call and the compiler will ERROR out, this isn't D compliant
but worked around via a WORD(MyWORD+1), but this is where it would really work well if Variants were in
play, Force a cast so the compiler knows which local overload to select at compile time..
 
 But this does not solve the ABS issue, this in it self should know at runtime what to do.

 The overloaded ABS(V:Variant):Variant seems to work well, I was wondering if putting it inside the
"Variants" unit so its only present when using Variants would work?
   
 I've done some test and the compiler seems to know the difference between using that one over the system.Abs for
non variant types.
6
Beginners / Re: PlaySound ('dog.wav', 0, snd_Async);
« Last post by jcaser1948 on Today at 05:57:25 pm »
The given procedure works fine,thank you very much.
But I have still trouble with the book2Delphi 7, the Bible where this procedure is used
Here the code from bokk,,adapted
Code: Pascal  [Select]
  1. unit abstanimf;
  2.  
  3. {$MODE Delphi}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
  9.     StdCtrls, Buttons, ExtCtrls, uplaysound;
  10.  
  11. type
  12.  
  13.   { TFormAnimals }
  14.  
  15.   TFormAnimals = class(TForm)
  16.     playsound1: Tplaysound;
  17.     LabelVoice: TLabel;
  18.     BtnVoice: TButton;
  19.     RbtnAnimal: TRadioButton;
  20.     RbtnDog: TRadioButton;
  21.     RbtnCat: TRadioButton;
  22.     procedure FormCreate(Sender: TObject);
  23.     procedure FormDestroy(Sender: TObject);
  24.     procedure BtnVoiceClick(Sender: TObject);
  25.     procedure RbtnAnimalClick(Sender: TObject);
  26.     procedure RbtnDogClick(Sender: TObject);
  27.     procedure RbtnCatClick(Sender: TObject);
  28.     procedure PlaySound(AWavFile: String; ASync: Boolean);
  29.  
  30.   private
  31.  
  32.   public
  33.     { Public declarations }
  34.  
  35.   end;
  36.  
  37.   TAnimal = class
  38.   public
  39.     constructor Create;
  40.     function GetKind: string;
  41.     function Voice: string; virtual;abstract;
  42.   private
  43.     Kind: string;
  44.   end;
  45.  
  46.   TDog = class (TAnimal)
  47.   public
  48.     constructor Create;
  49.     function Voice: string; override;
  50.     function Eat: string; virtual;
  51.   end;
  52.  
  53.   TCat = class (TAnimal)
  54.   public
  55.     constructor Create;
  56.     function Voice: string;override;
  57.     function Eat: string; virtual;
  58.   end;
  59.  
  60.  
  61. var
  62.  
  63.   FormAnimals: TFormAnimals;
  64.   MyAnimal: TAnimal;
  65.  
  66. implementation
  67.  
  68. {$R *.lfm}
  69.  
  70. procedure TFormAnimals.FormCreate(Sender: TObject);
  71. begin
  72.   MyAnimal := TDog.Create;
  73. end;
  74.  
  75. procedure TFormAnimals.FormDestroy(Sender: TObject);
  76. begin
  77.   MyAnimal.Free;
  78. end;
  79.  
  80. procedure TFormAnimals.BtnVoiceClick(Sender: TObject);
  81. begin
  82.   LabelVoice.Caption := MyAnimal.Voice;
  83. end;
  84.  
  85. constructor TAnimal.Create;
  86. begin
  87.   Kind := 'An animal';
  88. end;
  89.  
  90. function TAnimal.GetKind: string;
  91. begin
  92.   GetKind := Kind;
  93. end;
  94.  
  95. constructor TDog.Create;
  96. begin
  97.   Kind := 'A dog';
  98. end;
  99.  
  100. function TDog.Voice: string;
  101. Var VoiceSound:String;
  102. begin
  103.  
  104.    Voice := 'Arf Arf';
  105.     VoiceSound:= 'dog.wav';
  106.     FormAnimals.PlaySound(VoiceSound,true);
  107.  
  108. end;
  109.  
  110. function TDog.Eat: string;
  111. begin
  112.   Eat := 'A bone, please!';
  113. end;
  114.  
  115. constructor TCat.Create;
  116. begin
  117.   Kind := 'A cat';
  118. end;
  119.  
  120. function TCat.Voice: string;
  121. Var VoiceSound:String;
  122. begin
  123.   Voice := 'Mieow' ;
  124.   VoiceSound:= 'cat.wav';
  125.     FormAnimals.PlaySound(VoiceSound,true);
  126. end;
  127.  
  128. function TCat.Eat: string;
  129. begin
  130.   Eat := 'A mouse, please!';
  131. end;
  132.  
  133. procedure TFormAnimals.RbtnAnimalClick(Sender: TObject);
  134. begin
  135.   MyAnimal.Free;
  136.   MyAnimal := TAnimal.Create;
  137. end;
  138.  
  139. procedure TFormAnimals.RbtnDogClick(Sender: TObject);
  140. begin
  141.   MyAnimal.Free;
  142.   MyAnimal := TDog.Create;
  143. end;
  144.  
  145. procedure TFormAnimals.RbtnCatClick(Sender: TObject);
  146. begin
  147.   MyAnimal.Free;
  148.   MyAnimal := TCat.Create;
  149. end;
  150.  procedure  TFormAnimals.PlaySound(AWavFile: String; ASync: Boolean);
  151.  var
  152.   player: TPlaySound;
  153. begin
  154.   player := TPlaySound.Create(nil);
  155.   try
  156.     player.SoundFile := AWavFile;
  157.     if Async then player.PlayStyle := psAsync else player.PlayStyle := psSync;
  158.     player.Execute;
  159.   finally
  160.     player.Free;
  161.   end;
  162. end;
  163. end.
  164.  
It compile fine but when I get
unit abstanimf;

{$MODE Delphi}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
    StdCtrls, Buttons, ExtCtrls, uplaysound;

type

  { TFormAnimals }

  TFormAnimals = class(TForm)
    playsound1: Tplaysound;
    LabelVoice: TLabel;
    BtnVoice: TButton;
    RbtnAnimal: TRadioButton;
    RbtnDog: TRadioButton;
    RbtnCat: TRadioButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure BtnVoiceClick(Sender: TObject);
    procedure RbtnAnimalClick(Sender: TObject);
    procedure RbtnDogClick(Sender: TObject);
    procedure RbtnCatClick(Sender: TObject);
    procedure PlaySound(AWavFile: String; ASync: Boolean);

  private

  public
    { Public declarations }

  end;

  TAnimal = class
  public
    constructor Create;
    function GetKind: string;
    function Voice: string; virtual;abstract;
  private
    Kind: string;
  end;

  TDog = class (TAnimal)
  public
    constructor Create;
    function Voice: string; override;
    function Eat: string; virtual;
  end;

  TCat = class (TAnimal)
  public
    constructor Create;
    function Voice: string;override;
    function Eat: string; virtual;
  end;


var

  FormAnimals: TFormAnimals;
  MyAnimal: TAnimal;

implementation

{$R *.lfm}

procedure TFormAnimals.FormCreate(Sender: TObject);
begin
  MyAnimal := TDog.Create;
end;

procedure TFormAnimals.FormDestroy(Sender: TObject);
begin
  MyAnimal.Free;
end;

procedure TFormAnimals.BtnVoiceClick(Sender: TObject);
begin
  LabelVoice.Caption := MyAnimal.Voice;
end;

constructor TAnimal.Create;
begin
  Kind := 'An animal';
end;

function TAnimal.GetKind: string;
begin
  GetKind := Kind;
end;

constructor TDog.Create;
begin
  Kind := 'A dog';
end;

function TDog.Voice: string;
Var VoiceSound:String;
begin

   Voice := 'Arf Arf';
    VoiceSound:= 'dog.wav';
    FormAnimals.PlaySound(VoiceSound,true);

end;

function TDog.Eat: string;
begin
  Eat := 'A bone, please!';
end;

constructor TCat.Create;
begin
  Kind := 'A cat';
end;

function TCat.Voice: string;
Var VoiceSound:String;
begin
  Voice := 'Mieow' ;
  VoiceSound:= 'cat.wav';
    FormAnimals.PlaySound(VoiceSound,true);
end;

function TCat.Eat: string;
begin
  Eat := 'A mouse, please!';
end;

procedure TFormAnimals.RbtnAnimalClick(Sender: TObject);
begin
  MyAnimal.Free;
  MyAnimal := TAnimal.Create;
end;

procedure TFormAnimals.RbtnDogClick(Sender: TObject);
begin
  MyAnimal.Free;
  MyAnimal := TDog.Create;
end;

procedure TFormAnimals.RbtnCatClick(Sender: TObject);
begin
  MyAnimal.Free;
  MyAnimal := TCat.Create;
end;
 procedure  TFormAnimals.PlaySound(AWavFile: String; ASync: Boolean);
 var
  player: TPlaySound;
begin
  player := TPlaySound.Create(nil);
  try
    player.SoundFile := AWavFile;
    if Async then player.PlayStyle := psAsync else player.PlayStyle := psSync;
    player.Execute;
  finally
    player.Free;
  end;
end;


end.

try to execute it I getunit abstanimf;

{$MODE Delphi}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
    StdCtrls, Buttons, ExtCtrls, uplaysound;

type

  { TFormAnimals }

  TFormAnimals = class(TForm)
    playsound1: Tplaysound;
    LabelVoice: TLabel;
    BtnVoice: TButton;
    RbtnAnimal: TRadioButton;
    RbtnDog: TRadioButton;
    RbtnCat: TRadioButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure BtnVoiceClick(Sender: TObject);
    procedure RbtnAnimalClick(Sender: TObject);
    procedure RbtnDogClick(Sender: TObject);
    procedure RbtnCatClick(Sender: TObject);
    procedure PlaySound(AWavFile: String; ASync: Boolean);

  private

  public
    { Public declarations }

  end;

  TAnimal = class
  public
    constructor Create;
    function GetKind: string;
    function Voice: string; virtual;abstract;
  private
    Kind: string;
  end;

  TDog = class (TAnimal)
  public
    constructor Create;
    function Voice: string; override;
    function Eat: string; virtual;
  end;

  TCat = class (TAnimal)
  public
    constructor Create;
    function Voice: string;override;
    function Eat: string; virtual;
  end;


var

  FormAnimals: TFormAnimals;
  MyAnimal: TAnimal;

implementation

{$R *.lfm}

procedure TFormAnimals.FormCreate(Sender: TObject);
begin
  MyAnimal := TDog.Create;
end;

procedure TFormAnimals.FormDestroy(Sender: TObject);
begin
  MyAnimal.Free;
end;

procedure TFormAnimals.BtnVoiceClick(Sender: TObject);
begin
  LabelVoice.Caption := MyAnimal.Voice;
end;

constructor TAnimal.Create;
begin
  Kind := 'An animal';
end;

function TAnimal.GetKind: string;
begin
  GetKind := Kind;
end;

constructor TDog.Create;
begin
  Kind := 'A dog';
end;

function TDog.Voice: string;
Var VoiceSound:String;
begin

   Voice := 'Arf Arf';
    VoiceSound:= 'dog.wav';
    FormAnimals.PlaySound(VoiceSound,true);

end;

function TDog.Eat: string;
begin
  Eat := 'A bone, please!';
end;

constructor TCat.Create;
begin
  Kind := 'A cat';
end;

function TCat.Voice: string;
Var VoiceSound:String;
begin
  Voice := 'Mieow' ;
  VoiceSound:= 'cat.wav';
    FormAnimals.PlaySound(VoiceSound,true);
end;

function TCat.Eat: string;
begin
  Eat := 'A mouse, please!';
end;

procedure TFormAnimals.RbtnAnimalClick(Sender: TObject);
begin
  MyAnimal.Free;
  MyAnimal := TAnimal.Create;
end;

procedure TFormAnimals.RbtnDogClick(Sender: TObject);
begin
  MyAnimal.Free;
  MyAnimal := TDog.Create;
end;

procedure TFormAnimals.RbtnCatClick(Sender: TObject);
begin
  MyAnimal.Free;
  MyAnimal := TCat.Create;
end;
 procedure  TFormAnimals.PlaySound(AWavFile: String; ASync: Boolean);
 var
  player: TPlaySound;
begin
  player := TPlaySound.Create(nil);
  try
    player.SoundFile := AWavFile;
    if Async then player.PlayStyle := psAsync else player.PlayStyle := psSync;
    player.Execute;
  finally
    player.Free;
  end;
end;


end.
It compiles with the following warnings
abstanimf.pas(136,29) Warning: Constructing a class "TAnimal" with abstract method "Voice"
abstanimf.pas(41,14) Hint: Found abstract method: Voice(<TAnimal>;<var AnsiString>):AnsiString;
When I execute it I get Class exception Runerror(211)
in line 82 LabelVoice.Caption:=MyAnimalVoice;
When I go on I get
Abstract method called.

Press OK to ignore and risk data corruption.
Press Abort to kill the program.
It is very clear that I lack some understanding regardind the classes
by I have re read the chapter in the book and I do not find my error
The LFM code is
object FormAnimals: TFormAnimals
  Left = 733
  Height = 233
  Top = 170
  Width = 278
  ActiveControl = BtnVoice
  Caption = 'Animals'
  ClientHeight = 233
  ClientWidth = 278
  Color = clBtnFace
  Font.CharSet = ANSI_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  LCLVersion = '1.8.0.6'
  object LabelVoice: TLabel
    Left = 39
    Height = 17
    Top = 168
    Width = 201
    Alignment = taCenter
    AutoSize = False
    Caption = 'Voice'
    Font.CharSet = ANSI_CHARSET
    Font.Color = clBlack
    Font.Height = -16
    Font.Name = 'Arial'
    Font.Style = [fsBold]
    ParentColor = False
    ParentFont = False
  end
  object BtnVoice: TButton
    Left = 152
    Height = 33
    Top = 56
    Width = 89
    Caption = '&Voice'
    OnClick = BtnVoiceClick
    TabOrder = 0
  end
  object RbtnAnimal: TRadioButton
    Left = 24
    Height = 21
    Top = 40
    Width = 62
    Caption = '&Animal'
    OnClick = RbtnAnimalClick
    TabOrder = 1
  end
  object RbtnDog: TRadioButton
    Left = 24
    Height = 21
    Top = 72
    Width = 46
    Caption = '&Dog'
    Checked = True
    OnClick = RbtnDogClick
    TabOrder = 2
    TabStop = True
  end
  object RbtnCat: TRadioButton
    Left = 24
    Height = 21
    Top = 104
    Width = 43
    Caption = '&Cat'
    OnClick = RbtnCatClick
    TabOrder = 3
  end
  object playsound1: Tplaysound
    About.Description.Strings = (
      'Plays WAVE sounds in Windows or Linux'
    )
    About.Title = 'PlaySound'
    About.Height = 400
    About.Width = 400
    About.Font.Color = clNavy
    About.Font.Height = -13
    About.BackGroundColor = clCream
    About.Version = '0.0.7'
    About.Authorname = 'Gordon Bamber'
    About.Organisation = 'Public Domain'
    About.AuthorEmail = 'minesadorada@charcodelvalle.com'
    About.ComponentName = 'PlaySound'
    About.LicenseType = abModifiedGPL
    PlayCommand = 'play'
    left = 192
    top = 124
  end
end

Thanks again.This forum is my lifeboat

7
General / Re: ABS truncates a Variant float ?
« Last post by rvk on Today at 05:57:16 pm »
I see in the examples here that they are concentrating on negative numbers but of course this is also false for positive numbers.

Code: Pascal  [Select]
  1. var
  2.   X: Variant;
  3. begin
  4.   X := 5.5;
  5.   writeln('X = ',Abs(X)); // <-- gives 6

Maybe just forcing real in case of variant (like Delphi seems to do) is the best fix. Because there, even for an integer assigned to a Variant it seems that Abs() always results in a Real.

Quote
X = -1
VarIsFloat  : FALSE // <-- no real assigned
VarIsNumeric: TRUE
VarIsOrdinal: TRUE
After Abs()
X = 1
VarIsFloat  : TRUE // <-- converted to real
VarIsNumeric: TRUE
VarIsOrdinal: FALSE
8
LCL / Re: A simpler undo / redo class for TMemo
« Last post by fedkad on Today at 05:56:51 pm »
It seems a bit complicated and system dependent; but thank you very much ASerge.
9
General / Re: ABS truncates a Variant float ?
« Last post by Bart on Today at 05:55:35 pm »
Function ABS(V:Variant):Variant; Overload; inline;
Begin
  result := v;
  If VarIsNumeric(V) Then
    if V< 0 Then result := -v;
end;   [/code] :D

This will also allow code like this to compile:
Code: Pascal  [Select]
  1. var
  2.   S : String;
  3.  
  4. begin
  5.   S:='My very nice string';
  6.   S:=Abs(S);
  7. end;
  8.  

That would be bad.

Bart
10
FPSpreadsheet / Re: Cannot load ods file with formulas
« Last post by wp on Today at 05:52:44 pm »
And the formula with the external reference (or the DDE you mentioned in the first posts) is contained in the initial worksheet which you read, modify and write back, or is it in the modification that you make? In other words: Will fpspreadsheet have to read and write the (unsupported) external reference? Or will it only have to write it?
Pages: [1] 2 3 ... 10

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus