Recent

Author Topic: how to use the units -no information about this  (Read 13143 times)

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
how to use the units -no information about this
« on: January 13, 2022, 05:09:33 pm »
Hi All,

in source menu we can add units to uses section but for most of the units there is no information how to use it
could anyone help us ,where to find these information and how can we use these units in our programs.

thanks  :D

Thaddy

  • Hero Member
  • *****
  • Posts: 14357
  • Sensorship about opinions does not belong here.
Re: how to use the units -no information about this
« Reply #1 on: January 13, 2022, 05:46:43 pm »
If the units are seemingly undocumented, the sourcecode itself is the documentation. And FPC comes with all sourcecode for all packages and all units (100%). Often Google fpc <unitname> is enough if you are really stuck. Or the wiki.
Note it is not an ideal world, many units indeed lack outside documentation, but members of this forrum usually come up with examples when you ask a specific question about a specific unit.
« Last Edit: January 13, 2022, 05:50:34 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
Re: how to use the units -no information about this
« Reply #2 on: January 13, 2022, 06:04:13 pm »
thanks Thaddy for quick reply ,
yes true a lot of units have no information about using it , but is there any method or a way to learn about units , for example you have mentioned the source code itself but i think it is complicated for new person to figure out how to convert it to a sample

thanks

Thaddy

  • Hero Member
  • *****
  • Posts: 14357
  • Sensorship about opinions does not belong here.
Re: how to use the units -no information about this
« Reply #3 on: January 13, 2022, 06:31:20 pm »
Well, just ask on the forum... If a unit is unclear to you, there are ions of experience available here and beginners will never be ignored.. Often the people who wrote such a unit in the first place 8) are here as well.
« Last Edit: January 13, 2022, 06:36:07 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

speter

  • Sr. Member
  • ****
  • Posts: 349
Re: how to use the units -no information about this
« Reply #4 on: January 14, 2022, 12:14:04 am »
alaa123456789 are you asking:
  (a) how do I add units to my application(s)? or
  (b) how do I use the units included with fpc &/or lazarus?

If (b) then I'd recommend what Thaddy wrote (ask the forum; usually about a particular function, procedure or component); if (a) then have a look at chapter 16 in the fpc pascal reference guide (https://www.freepascal.org/docs-html/ref/ref.html).

There are also numerous (PDF) books that give information about (a) and (b). :)

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
Re: how to use the units -no information about this
« Reply #5 on: January 14, 2022, 11:46:52 am »
Quote
alaa123456789 are you asking:
  (a) how do I add units to my application(s)? or
  (b) how do I use the units included with fpc &/or lazarus?
hi , i am asking about using units (which in lazarus as well in fpc folder) , could you please share if there is a books descripting the units with examples .

for example @ Thaddy , RSVG unit how to use it to show svg file on the form

thanks

dbannon

  • Hero Member
  • *****
  • Posts: 2789
    • tomboy-ng, a rewrite of the classic Tomboy
Re: how to use the units -no information about this
« Reply #6 on: January 14, 2022, 12:19:01 pm »

Its often useful to search both the wiki and the forum, I just found a number of potential useful hits doing just that, 'svg'.

There is an example buried down in your Lazarus dir that talks about displaying an SVG in a PDF, I'd expect the process would be somewhat similar.

components/cairocanvas/example/cairoprog.lpr

Give those a try and come back with specific questions here if necessary. Generally, specific questions that start with "I tried XXX but YYY happened" get some pretty answers !

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
Re: how to use the units -no information about this
« Reply #7 on: January 14, 2022, 01:02:45 pm »
THE SPECIFIC QUESTION IS THIS
Quote
RSVG unit how to use it to show svg file on the form OR TIMAGE
THE CAIRO EXAMPLE SHOW ONLY HOW TO PRINT OUT FILE AS SVG
THANKS

speter

  • Sr. Member
  • ****
  • Posts: 349
Re: how to use the units -no information about this
« Reply #8 on: January 15, 2022, 12:29:06 am »
THE SPECIFIC QUESTION IS THIS
Quote
RSVG unit how to use it to show svg file on the form OR TIMAGE
THE CAIRO EXAMPLE SHOW ONLY HOW TO PRINT OUT FILE AS SVG
THANKS
Have a look at https://forum.lazarus.freepascal.org/index.php?topic=36910.0 (it came up from a google search for "lazarus svg". It does not use "RSVG" though (it uses BGRABitmap).

cheers
S.
« Last Edit: January 15, 2022, 03:52:39 am by speter »
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

dbannon

  • Hero Member
  • *****
  • Posts: 2789
    • tomboy-ng, a rewrite of the classic Tomboy
Re: how to use the units -no information about this
« Reply #9 on: January 15, 2022, 01:34:19 am »
THE SPECIFIC QUESTION IS THIS
Quote
RSVG unit how to use it to show svg file on the form OR TIMAGE
....

Are you aware that all caps is regarded as shouting ?  I'll assume you are not so aware.

My post suggested you search the wiki and forum before asking you specif question. Did you ?

In the forum, I found over 200 hits for 'svg', a small number are likely to hold the key to your problem. Did you look through them ?  Pick out one or two that looked promising, maybe mention the ones you tried out. Then you could format your question in the manner I suggested.

Davo


Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: how to use the units -no information about this
« Reply #10 on: January 15, 2022, 04:09:10 am »
RSVG unit how to use it to show svg file on the form

rsvg is a partial header for librsvg,  version 2 specifically.

I found version 2.2 on my laptop, inside GIMP binary folder.

Made a copy of rsvg file into a new project folder and changed the name of the library to match the one I have. I also defined DYNLIB to get it to work with the dll.

I found the man pages for librsvg, not long after that I did a quick test:
Code: Pascal  [Select][+][-]
  1. uses
  2. ...
  3.   ,rsvg
  4.   ,gdk2pixbuf;
  5. ...
  6. procedure Test_rsvg(fn:string; Canvas:TCanvas);
  7. var
  8.   e:PGError;
  9.   h:PRsvgHandle;
  10.   buf:PGdkPixbuf;
  11.   channels,bits_per_sample,width,height,rowstride:LongInt;
  12.   colorspace:TGdkColorspace;
  13.   alpha:boolean32;
  14.   pixels:Pguchar;
  15.   y,x:integer;
  16.   pb:PByte;
  17. begin
  18.   rsvg_init;
  19.  
  20.   //read a file
  21.   h:=rsvg_handle_new_from_file(pchar(fn),e);
  22.   if h=nil then
  23.   begin
  24.     LogLn('rsvg_handle_new_from_file: ',e^.message);
  25.     exit;
  26.   end;
  27.  
  28.   //Get pix
  29.   buf:=rsvg_handle_get_pixbuf(h);
  30.  
  31.   //Get pix info
  32.   colorspace:=gdk_pixbuf_get_colorspace(buf);
  33.   channels:=gdk_pixbuf_get_n_channels(buf);
  34.   alpha:=gdk_pixbuf_get_has_alpha(buf);
  35.   bits_per_sample:=gdk_pixbuf_get_bits_per_sample(buf);
  36.   pixels:=gdk_pixbuf_get_pixels(buf);
  37.   width:=gdk_pixbuf_get_width(buf);
  38.   height:=gdk_pixbuf_get_height(buf);
  39.   rowstride:=gdk_pixbuf_get_rowstride(buf);
  40.  
  41.   //Draw pix
  42.   pb:=pixels;
  43.   for y:=0 to height-1 do
  44.   begin
  45.     for x:=0 to width-1 do
  46.     begin
  47.       Canvas.Pixels[x,y]:=RGBToColor((pb+0)^,(pb+1)^,(pb+2)^);
  48.       inc(pb,4);
  49.     end;
  50.   end;
  51.  
  52.   //clean up
  53.   rsvg_handle_close(h,e);
  54.   rsvg_term;
  55. end;

This to get you started. I tried it on one file and it seems right.
« Last Edit: January 15, 2022, 04:15:50 am by engkin »

Thaddy

  • Hero Member
  • *****
  • Posts: 14357
  • Sensorship about opinions does not belong here.
Re: how to use the units -no information about this
« Reply #11 on: January 15, 2022, 07:09:39 am »
Also have a look at the language reference guide:
https://www.freepascal.org/docs-html/current/ref/refse112.html#x233-25700016.2

And tis
https://www.thoughtco.com/anatomy-of-delphi-unit-for-beginners-4091943
Note that is for delphi but covers FPC too. *.dpr  equals *.lpr. The unit parts work out of the box in {$mode delphi}
« Last Edit: January 15, 2022, 07:22:09 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
Re: how to use the units -no information about this
« Reply #12 on: January 15, 2022, 12:33:33 pm »
THE SPECIFIC QUESTION IS THIS
Quote
RSVG unit how to use it to show svg file on the form OR TIMAGE
....

Are you aware that all caps is regarded as shouting ?  I'll assume you are not so aware.
i don't like to argue with you about capital and small letter meaning, but i never been mean to anyone
thanks for your advise , the topic is how to use the units as i said for example Rsvg but there are many units is not having information , i know about bgra component , but to learn how to use the units with ide,fpc is much better and useful

thanks

dbannon

  • Hero Member
  • *****
  • Posts: 2789
    • tomboy-ng, a rewrite of the classic Tomboy
Re: how to use the units -no information about this
« Reply #13 on: January 15, 2022, 12:51:59 pm »
...... but there are many units is not having information

Yes, I agree. The "getting a first start" information is missing in a lot of places. I have been trying to get some interest in indexing and documenting the existing set of examples (there are well over 200 but hard to find the one you want) in https://forum.lazarus.freepascal.org/index.php/topic,57680.0.html but sadly I am not seeing any interest and will abandon the idea tomorrow.

.... i know about bgra component , but to learn how to use the units with ide,fpc is much better and useful

bgra is  FPC just as much as Rsvg is. And probably bgra is more widely used and better supported.  I have only used it once in a small tryout that I abandoned because I was disturbed about how much it enlarged my binary. But it was definitely quite easily used with a most things fairly obvious. Given, as I said, its widely used, heavily discussed and under active development, might be a good choice.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: how to use the units -no information about this
« Reply #14 on: January 15, 2022, 12:57:55 pm »
typing the function name and pressing F1 helps if you have the help installed. Otherwise, first google to find which function you need (mostly fro the forum here) and then google for that function name to see in which unit it resides.

It's advisable to do that anyway if you're not sure, because things get added and move around. Like, the units that hold the same functions, but for UTF-8, or functions that don't rely on Windows, etc.

I tend to google first if I think something is difficult and could be much simpler, before I use the complex one or build it myself.

 

TinyPortal © 2005-2018