Difference between revisions of "Source Examples"

From Freepascal Amiga wiki
Jump to navigation Jump to search
(activated syntax highlighting)
Line 8: Line 8:
  
 
Basic hello world program:
 
Basic hello world program:
  Program HelloWorld;
+
<source lang="pascal">
  Begin
+
Program HelloWorld;
    Writeln('Hello World');
+
Begin
  End.
+
  Writeln('Hello World');
 +
End.
 +
</source>
  
 
How to check if the program started from Wanderer/Workbench
 
How to check if the program started from Wanderer/Workbench
 +
<source lang="pascal">
 
   program WBStart;
 
   program WBStart;
 
   begin
 
   begin
Line 21: Line 24:
 
       writeln('Started from CLI');
 
       writeln('Started from CLI');
 
   end.
 
   end.
 +
</source>
  
 
One example, Put a message to a named port:
 
One example, Put a message to a named port:
 +
<source lang="pascal">
 
  function SafePutToPort(Msg: PMessage; Portname: string): Integer;
 
  function SafePutToPort(Msg: PMessage; Portname: string): Integer;
 
  var
 
  var
Line 39: Line 44:
 
   Permit();
 
   Permit();
 
  end;
 
  end;
 +
</source>

Revision as of 17:26, 25 August 2013

Source Examples

On this page Source example are going to collect (or links to it) which working on AROS freepascal



Basic hello world program:

Program HelloWorld;
Begin
  Writeln('Hello World');
End.

How to check if the program started from Wanderer/Workbench

  program WBStart;
  begin
    if assigned(AOS_WbMsg) then
      writeln('Started from WB')
    else
      writeln('Started from CLI');
  end.

One example, Put a message to a named port:

 function SafePutToPort(Msg: PMessage; Portname: string): Integer;
 var
   Port: PMsgPort;
   PName: PChar;
 begin
   Result := -1;
   PName := PChar(Portname + #0);
   Forbid();
   Port := FindPort(PName);
   if Assigned(Port) then
   begin
     PutMsg(Port, Msg);
     Result := 0;
   end;
   Permit();
 end;