* * *

Recent Posts

Pages: [1] 2 3 ... 10
1
Games / Re: Simple utility function for Allegro users
« Last post by Ñuño_Martínez on Today at 01:51:36 pm »
Instead of use a global variable, I recommend you to use a more Object Oriented approach (even without use of CLASSes, as you'll see).  That way you'll be able to manage your bitmaps more easy and grouped (i.e. PlayerImages, Alien1Images, Alien2Images...).  Even loading images would be more easy.

Also, you can reproduce the same to manage sound samples.

For example:
Code: Pascal  [Select]
  1. TYPE
  2. (* Contains a list of bitmaps. *)
  3.   TBitmapList = RECORD
  4.     Bmp: ARRAY OF ALLEGRO_BITMAPptr;
  5.     Count: INTEGER;
  6.   END;
  7.  
  8.  
  9.  
  10. (* Finds an empty place. *)
  11.   FUNCTION FindEmptyBmp (VAR aList: TBitmapList): INTEGER;
  12.   VAR
  13.     Ndx: INTEGER;
  14.   BEGIN
  15.     IF Length (aList.Bmp) < 1 THEN
  16.     BEGIN
  17.       aList.Count := 0;
  18.       EXIT (-1)
  19.     END;
  20.     FOR Ndx := 0 TO (aList.Count - 1) DO
  21.       IF aList.Bmp[Ndx] = NIL THEN EXIT (Ndx);
  22.     FindEmptyBmp := -1
  23.   END;
  24.  
  25.  
  26.  
  27. (* Adds a new bitmap.  Returns index. *)
  28.   FUNCTION AddBmp (VAR aList: TBitmapList; aBmp: ALLEGRO_BITMAPptr): INTEGER;
  29.   VAR
  30.     MyNdx: INTEGER;
  31.   BEGIN
  32.   { Find an empty place. }
  33.     MyNdx := FindEmptyBmp (aList);
  34.     IF MyNdx < 0 THEN
  35.     BEGIN
  36.     { If there's no space reserve more space. }
  37.       IF aList.Count < 1 THEN
  38.       BEGIN
  39.         SetLength (aList.Bmp, 8);
  40.         FOR MyNdx := 0 TO 7 DO aList.Bmp[MyNdx] := NIL
  41.       END
  42.       ELSE IF Length (aList.Bmp) <= aList.Count THEN
  43.       BEGIN
  44.         SetLength (aList.Bmp, aList.Count * 2);  
  45.         FOR MyNdx := aList.Count TO HIGH (aList.Bmp) DO
  46.           aList.Bmp[MyNdx] := NIL
  47.       END;
  48.     { Where to put the new bitmap. }
  49.       MyNdx := aList.Count;
  50.  
  51.       INC (aList.Count)
  52.     END;
  53.     aList.Bmp[MyNdx] := aBmp;
  54.     AddBmp := MyNdx
  55.   END;
  56.  
  57.  
  58.  
  59. (* Removes (and destroys) a bitmap. *)
  60.   PROCEDURE DestroyBitmap (VAR aList: TBitmapList; CONST Ndx: INTEGER);
  61.   BEGIN
  62.   { Avoid go outside the list. }
  63.      IF (0 > Ndx) OR (Ndx >= aList.Count) THEN Exit;
  64.      IF aList.Bmp[Ndx] = NIL THEN Exit;
  65.   { Destroy. }
  66.      al_destroy_bitmap (aList.Bmp[Ndx]);
  67.      aList.Bmp[Ndx] := NIL
  68.   END;
  69.  
  70.  
  71.  
  72. (* Destroy all bitmaps. *)
  73.   PROCEDURE ClearBitmapList (VAR aList: TBitmapList);
  74.   VAR
  75.     Ndx: INTEGER;
  76.   BEGIN
  77.     FOR Ndx := 0 TO (aList.Count - 1) DO
  78.       IF aList.Bmp[Ndx] <> NIL THEN al_destroy_bitmap (aList.Bmp[Ndx]);
  79.     SetLength (aList.Bmp, 0);
  80.     aList.Count := 0
  81.   END;
  82.  

Finding and fixing flaws and bugs are left as exercise (I didn't test the code so I'm not sure if it is correct).

If you want to use CLASSes, you can still using the ARRAY approach, but you would use TList or TFPList or any of the generics version instead.

[edit] I've fixed some very obvious flaws.
2
Spanish / [Resuelto] Ocultar valores en cero con LastReport
« Last post by esdonis on Today at 01:34:10 pm »
Perfecto

Muchas Gracias por la ayuda
3
Beginners / Re: Problems readig archive files
« Last post by jcaser1948 on Today at 01:27:20 pm »
Dear Howard Pc
I Am trying yor solution
Here the code so far  {---------------------------------------------------------------------------}
Code: Pascal  [Select]
  1. PROCEDURE TForm1.ReadFile;
  2.  
  3. VAR
  4.   filename:string;
  5.   LocalMotorname:Textfile;
  6.    sl: TStringList;
  7.    BEGIN
  8.     OpenDialog1.Execute ;
  9.  
  10.    filename:= OpenDialog1.filename;
  11.     ShowMessage(Filename);
  12.    sl:=TStringList.Create;
  13.            try
  14.     sl.LoadFromFile(OpenDialog1.Filename);
  15.     Assert(sl.Count=81,'Unexpected number of lines in '+OpenDialog1.Filename);
  16.     dia:=sl[0];
  17.     mes:=sl[1];
  18.     anho:=sl[2];
  19.     motortyp:= sl[3];
  20.     Bearbeiter:= sl[4];
  21.     Statorblechnr:= sl[5];
  22.     Rotorblechnr:=sl[6];
  23.     Angebotsnummer:= sl[7];
  24.     kenrot :=StrToFloat(sl[8]);
  25.     schltg := sl[9];
  26.     polzahl              .....
  27. Kenrot ,schltg....are real numbers , since this is a motorcalculationsprogramm.
  28. When  I try to convert Kenrot  from a String to a real number Iget
  29. datenfile1.pas(1949,14) Error: Incompatible types: got "Extended" expected "LongInt"
  30. Any suggestions?
  31. [/quote]
  32. Sorry,
  33. Knerot,Schltg... were defined as  integers
  34. Now it works
  35.  kenrot :=StrToInt(sl[8]);
  36.     schltg :=StrToInt (sl[9]);
  37.  
  38.     polzahl :=StrToInt (sl[10]);
     


Could you give me a suggestion as how the Writefile would look like?
Thanks
4
FPC development / Re: StringReplace extremely slow with big strings
« Last post by JuhaManninen on Today at 01:11:37 pm »
2. CodeUnit is some type of variable. But I could no find more info about it.
No. It is a concept of Unicode. It is the smallest atomic building block. A code point can consist of one or more code units.
In Pascal terms it is type Char, a byte with UTF-8 and a word with UTF-16.
See:
 https://en.wikipedia.org/wiki/Character_encoding#Terminology
and search for "code unit".
5
FPC development / Re: StringReplace extremely slow with big strings
« Last post by CM630 on Today at 12:58:59 pm »

1. What I got from the example is that I should keep PosEx and Length in StringReplaceNew.


2. CodeUnit is some type of variable. But I could no find more info about it.
3. My current (old) implementation of StringReplaceNew messes the strings up.
4. I will try RAW's solution and feedback.
    Edit: I tried it. My app crashes with a range check error. :(
6
FPC development / Re: StringReplace extremely slow with big strings
« Last post by JuhaManninen on Today at 12:01:32 pm »
If you replace ansi with ansi, plz do NOT use string in Lazarus: that is UTF8. Rename string to AnsiString.
Thaddy, in Lazarus by default String = AnsiString.
You should however use type String always because the code is then compatible with Delphi and with future mode DelphiUnicode solutions.
Remember, Ansi...() functions like AnsiUpperCase() work transparently with different encodings then.

If someone still uses the old Windows codepages, then please switch to Unicode.

CM630, please see the example:
 http://wiki.lazarus.freepascal.org/UTF8_strings_and_characters#Search_and_copy
Pos() and PosEx() work in StringReplaceNew for the same reasons they work in the given example.
CodeUnit (Pascal Char) resolution is still very useful with variable width encodings, and is fast.
7
Beginners / Re: Problems readig archive files
« Last post by howardpc on Today at 10:28:23 am »
Code snippets are useless. Show the entire code.

Is kenrot declared as an Integer rather than Single or Double?
In what format are the numbers stored in the text file you are reading?
8
Beginners / Re: Problems readig archive files
« Last post by Handoko on Today at 10:15:28 am »
~~~ sorry off topic ~~~

Hello sir. When posting in this forum you can make your code more readable by using code tag. First you select the text then click the code tag and choose Pascal. See the image below:
9
Android / Re: Android Module Wizard
« Last post by trevor on Today at 10:15:02 am »
How to add 2/3/4/5 lines to all items of Android Native ListView?
10
FPC development / Re: StringReplace extremely slow with big strings
« Last post by CM630 on Today at 10:12:27 am »
@Thaddy, I am not sure that I understood you right and that you understood me. I am replacing Ansi with Ansi in an UTF8 string.

In other words: Strings which I am replacing are with ascii code <127 (basic Latin, &%$# etc). But the sting which contains them may also contain uтf8 characters.
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