[Lazarus] making lazarus from source failed (linux mint)

2015-09-17 Thread Xiangrong Fang
Hi All,

As I cannot find fpc 2.6.4 for linux mint (the highest version for deb
package is 2.4.2).  I need to compile lazarus from source (as the official
deb package depends on fpc 2.6.4, while the mint system only provide 2.6.2).

I got this error: Fatal: (10022) Can't find unit system used by fcllaz

This is a "famous" error. I checked google, and know that it probably
caused by some directory configuration problems.

The command being executed by the make file is:

/usr/share/fpc-2.6.4/bin/ppcx64 -MObjFPC -Scghi -O1 -g -gl -l -vewnhibq
-Fu. -FE. -FU../units/x86_64-linux -Cg -dx86_64 fcllaz.pas

I don't know where does the options come from (especially the -FU option),
probably a fpc.cfg file somewhere.   My fpc was installed by the official
install.sh script to my local dir, and I moved the entire directory to
/usr/share/fpc-2.6.4 made a symbol link /usr/share/fpc, then added that
directory to $PATH.

Could anyone explain how FPC find its configuration file, and how to solve
the compile problem?

Thanks!
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] IDE maximize editor option?

2015-08-25 Thread Xiangrong Fang
Hello,

Is there an option to maximize the editor (with tab support) in case I want
to take advantage of Lazarus syntax and hyper link support, but without the
need to use any GUI stuff (i.e. not using vcl).  This would be handy for
programming console or low level stuff in freepascal.

Thanks!
Xiangrong
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TMemo: behavior difference between linux and windows

2015-08-06 Thread Xiangrong Fang
I tested with a simple program and confirmed leledumbo's test. I will keep
an eye on it, if this happen again later.



2015-08-05 23:35 GMT+08:00 leledumbo :

> > TMemo.OnChange is triggered while Memo content is updated
> PROGRAMATICALLY,
> while on Linux (GTK) it is not triggered.
>
> Tested on both GTK2 and QT, OnChange fires when Memo1 content is updated
> programmatically.
>
> Lazarus 1.5 r49595
>
>
>
>
> --
> View this message in context:
> http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-TMemo-behavior-difference-between-linux-and-windows-tp4043450p4043452.html
> Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com.
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] TMemo: behavior difference between linux and windows

2015-08-05 Thread Xiangrong Fang
Hi There,

I found that On Windows, TMemo.OnChange is triggered while Memo content is
updated PROGRAMATICALLY, while on Linux (GTK) it is not triggered.

For this reason, I have to use OnKeyPress instead of OnChange to make my
program behave same on both platform.

Is this a know problem (probably because of the underlying widget set), or
is it considered a bug?

Thanks!
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Owner of a TCanvas

2015-07-27 Thread Xiangrong Fang
Hi There,

Can I somehow get the object which owns a Canvas? e.g.:

function GetCanvasOwner(ACanvas: TCanvas): TObject;
begin
   Result := ACanvas.Owner;
end;
pb := TPaintBox(GetCanvasOwner(pb.Canvas);

Thanks!
Xiangrong
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] cross platform pre-compile processing

2015-06-19 Thread Xiangrong Fang
Hi,

I need to run a program before compile my program, so I set it in lazarus's
project settings. It works fine, but, how can I make it a platform
dependent config, i.e.

run "prepare" if the project is compiled under linux, and run "prepare.exe"
if it is compiled on Windows.

Thanks!

Xiangrong
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] SQLDB: how to use TSQLTransaction

2015-04-11 Thread Xiangrong Fang
2015-04-11 15:41 GMT+08:00 SPRL AFOR :

Michael's comments do not need further explanation
>
> If you want an Sql statement be executed immediately attach an
> TSqlTransaction to a DB component, attach the TSqlQuery  to the transaction
> and enclose it between a StartTransaction and a Commit.
>
> TR.StartTransaction;
> qr.ExecSql;
> TR.Commit;
>
> The Commit matters as well
>

​As a matter of fact, I think yours and Michael's reply both answered part
of my questions but not all. I am now clear about the meaning of
RowsAffected returning value -1, but I am still not clear about WHY
*sometime* I need to use Commit, but other times it is *not* necessary?

If the rule with SQLDB is that I always need to use Commit, fine, I am
perfectly fine with this rule. But, in my function, the Commit is not
necessary, even without it, the UPDATE takes effect.  That's why I am
confused: when must I use Commit, and when it is optional?  Please note
that:

1) I am using SQLDB without a form, so all properties are at their default
value, unless I explicitly change them -- I don't know there are options
like
sqoAutoCommit
​, and I didn't set any properties for sqldb components.​

2) I am using SQLite3, on Ubuntu 14.10 64bit.​


3) I even thought that Commit is necessary when using INSERT, but is
optional if you use UPDATE, but that logic seems weird...​


If you could explain why the behaviors are different that will be very
helpful.

​Thank you very much!​
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] SQLDB: how to use TSQLTransaction

2015-04-10 Thread Xiangrong Fang
Hi All,

Sorry that I don't know if SQLDB belongs to fpc or lazarus, so I posted to
both lists.

I am confused about the use of transaction in SQLDB. I tried to use in in
my non-gui app. Here is the code:

function TPortfolio.ConfirmTransaction(id: Integer): Boolean;
begin
  with qr do begin
SQL.Text := Format('UPDATE records SET status=%d WHERE id=%d AND
status=%d',
  [TR_SUCCESS, id, TR_PENDING]);
ExecSQL;
WriteLn('Confirming: ', id, ', affected: ', RowsAffected);
//tr.Commit;
//WriteLn('Confirming: ', id, ', affected: ', RowsAffected);
Result := RowsAffected > 0;
  end;
end;
It seems that I must assign a TSQLTransaction object to the TSQLQuery
object, otherwise it doesn't work. I also found that without call
tr.Commit, the ExecSQL will not take effect, at least for INSERT
statements.

In the above function, I found the first WriteLn will output rows-affected
as 1, and the 2nd (after tr.Commit) will output rows-affected as -1!  I
then commented out the tr.Commit; statement, it STILL worked.

Now my questions are:

1. How to control the use of transactions in SQLDB? Sometime I do NOT want
transaction, but want the DDL/DML statement to be executed immediately.
Why sometime SQLDB's ExecSQL won't take effect if not followed by a Commit?
BTW, I tried to set tr.Active to true/false before execute the sql, but it
seems not making a difference?

2. What is the meaning of -1 as returned by RowsAffected?

Thanks!

Xiangrong
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Is this a bug? (scrollbar overlay)

2015-04-05 Thread Xiangrong Fang
Hi All,

Please take a look at the attached screenshot. ScrollBar1 is set to align
bottom, and PaintBox1 is set to align client.

The problem is I expect the height of PaintBox1 to be the ClientHeight of
Form1 minus the hight of ScrollBar1.  In fact, the scollbar does not push
the paintbox upward, but looks like floating over it.

Can I make the scrollbar align below the paintbox instead of floating on
top of it?

btw, I am using Lazarus 1.2.6 on Ubuntu 14.10 64bit.

Thanks!

Xiangrong
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Problem using "watch"

2014-11-15 Thread Xiangrong Fang
When I do single step, I want to know the value of a variable, so I hover
mouse pointer over it. I got strange thing as shown in attached window, how
to view the value of Integer "c", in my case?

Thanks!

Xiangrong
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Problem in the debugger?

2014-09-29 Thread Xiangrong Fang
Hi All,

While I hover mouse over a variable during debugging, I often get popups
shown as attached.

Is there any known problem of the debugger, or I have to do some
setup/tweak?

Thanks!

Xiangrong
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] PostMessage return value

2014-09-19 Thread Xiangrong Fang
2014-09-19 18:23 GMT+08:00 Michael Schnell :

>  On 09/18/2014 10:32 AM, Xiangrong Fang wrote:
>
> Unfortunately I do not get this working. When I instantiate TEvents
> instead of TCriticalSections (and don't do much with same)  the GUI
> freezes. In fact I do this in the "OnCreate" Event of the main Form and
> (not always but mostly) no child components are shown (but the close button
> [x] of the form still works.
>

As far as I tried, you cannot use RTLEventWaitFor in main thread, otherwise
the gui will freeze. Don't know what you did...
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] PostMessage return value

2014-09-18 Thread Xiangrong Fang
2014-09-18 19:34 GMT+08:00 Michael Schnell :

>
> I think, in the other mail, I did explain how "Wait" is supposed to work
> in TThreadPool.
>
>
Initially, when the threadpool is created, Wait is hold by the main thread,
so the worker just wait there, no problem, but after the worker thread get
the CS, it started working, then RELEASE the CS.

This is when the problem arise: after worker release the CS, how do you
ensure it is the MAIN thread who will get the CS next, NOT the worker
thread again?

That is my question, which I don't think you answered.

Thanks,
Xiangrong
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] PostMessage return value

2014-09-18 Thread Xiangrong Fang
2014-09-18 17:55 GMT+08:00 Michael Schnell :

>
> Sven made me know that by "event" you did not mean an object pascal
> language "Event" (i.e. a callback), but a "TEvent instance".
>

Sorry, I mean *neither*.  I mean an RTLEvent. See this page:

http://www.freepascal.org/docs-html/rtl/system/rtleventcreate.html

What I need help to understand is, repeating my previous email:

While using ACriticalSection.Acquire, two threads are COMPETING for a
"token" to do certain task, hence you do not know WHICH thread eventually
get that token, although statistically each thread have the same chance of
getting the token in the long run.

While calling RTLeventWaitFor(), the calling thread gives up
chance to run, blocked until another thread calls RTLeventSetEvent() to
notify it.

If the above understanding is correct, then I believe only RTLEvent can
"synchronize" threads, i.e., let them run in a *determined* order. While
CriticalSection ONLY provide a way to protect a shared resource is not
accessed simultaneously.

Alternatively, I have another "design":

procedure TMyThread.Execute;
begin
  while not Terminated do begin
if FCondition = true then begin
  //do the job...
end;
  end;
end;

In the code above, I do not use event or critical section is it enough to
let this thread wait there, without wasting cpu time, until FCondition is
set (externally by the main thread)?

Thanks!

Xiangrong
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] PostMessage return value

2014-09-18 Thread Xiangrong Fang
2014-09-18 16:13 GMT+08:00 Michael Schnell :

>
> I did the TThreadPool class just for fun. I'll compare the two thingies
> and come back with some comments.
>
>
​I don't quite understand the logic or difference between critical section ​

​and events. My feeling is that to do synchronization you will have to use
event (I will do some test to verify that).  Because when you use critical
section, like in your ThreadPool:

procedure TThreadPoolThread.Execute;
begin
  while not Terminated do begin
Wait.Aquire;
...
  end;
end;

You are actively try to aquire the CS.  i.e. After you finish this loop and
notify the main thread, how do you ensure which thread will get this CS
next? The main thread or this worker thread?

​But if you use something like this (I don't know if the syntax or usage is
correct, just show my thinking):

procedure TThreadPoolThread.Execute;
begin
  while not Terminated do begin
RTLEventWaitFor(Wait);
...
  end;
end;
​
​Then, you are PASSIVELY wait for the event which will be set/reset from
OUTSIDE this working thread.

That's what confused me how can you use a CS for the purpose of thread
synchronization!

Yesterday I read your ThreadPool source code, and cannot understand how you
control which thread can get the "Wait" CS, rather than just let the 2
thread compete for it. Could you please explain the logic behind this?

Thanks!

Xiangrong​
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] PostMessage return value

2014-09-17 Thread Xiangrong Fang
2014-09-17 16:09 GMT+08:00 Michael Schnell :

>
> Here you are.
>

It is strange that it works on one computer but does not work (or partially
work) on another -- causing SIGSEGV.  Both running same environment -
Ubuntu 14.04 x86_64 fpc 2.6.4 laz1.2.4.

I don't understand how the critical section works.   I try to write a test
program, which does the following:

The main thread create a predefined number of threads, which start running
on creation. The thread's wait for a critical section variable, when
acquired, try to crack a given integer, see if it is prime number or not,
report back to main thread about the result and get the next number to
crack from main thread.  The main thread output crack result of every
thread in a memo box.

I simply don't know how to coordinate the threads. And got many strange
errors like

Semaphore init failed (maybe too many running threads)?
SIGABT
SIGTRAP

something wrong in raise.c, laz asked me if I want to locate myself,
blahblah.


May I send you my source, or you can write a demo for me?  Thanks a lot!

Xiangrong
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] PostMessage return value

2014-09-16 Thread Xiangrong Fang
2014-09-16 23:08 GMT+08:00 Michael Schnell :

> I added a notify event for having both a single task and all task issue an
> event when having don the scheduled work.


But where is the source please?
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] PostMessage return value

2014-09-16 Thread Xiangrong Fang
Hi Michael,

Could you please post it somewhere, e.g. github?

Thanks!

2014-09-16 19:44 GMT+08:00 Michael Schnell :

> I did a draft of a TThreadPool class.
>
> Most of it works (creating assigning and re-assigning tasks works,
> stopping the thing still produces an exception).
>
> If anybody wants to test it I can post the project.
>
> -Michael
>
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] PostMessage return value

2014-09-15 Thread Xiangrong Fang
2014-09-15 22:30 GMT+08:00 Michael Schnell :

> Is that ok? To be exact, when a thread's execute() finished, it will go to
> a "sleep" status,
>
> No. It will die.
>
>   and can be reused by calling execute() again, right?
>
> AFAIK: No.
>

What's the meaning of "die"? By "calling execute()" I simply mean call its
Start() method. I will create the thread in "Suspended" mode, i.e.
Create(True).  So I hope I can Start() it again after Execute() ended.

That's what I understand where the document said Resume() is deprecated and
replaced by Start(), which means, Start() can be called multiple times??
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] PostMessage return value

2014-09-15 Thread Xiangrong Fang
2014-09-15 21:44 GMT+08:00 Michael Schnell :

>
> Performance wise it's better not to destroy and create your threads but to
> manage a thread pool and assign work to the threads as appropriate.
>
> Here you would have the threads wait for work  e.g. by trapping themselves
> in a TCriticalSection for each one.
>
> Now the Main thread can easily free a thread after it assigned work to it
> (e.g. by providing a callback function that is to be called in
> TThread.Execute). If work is done, the Thread could notify the manager (in
> the main thread) by Application.QueueAsyncCall or TThread.Queue. TThread.
> Synchronize would not harm in this case either, as the thread at that time
> has nothing to do anyway.
>

That's exactly what I planed to do. But I don't know "CriticalSections" can
be used in here.  My original thinking is that, by the end of Execute, I
call either PostMessage or QueueAsyncCall to notify main thread that the
current thread finished its work.  The main thread, in its message handler
then know from a status variable that this thread is in suspended status,
then assign a new work to it and call its Execute() method again.

Is that ok? To be exact, when a thread's execute() finished, it will go to
a "sleep" status, and can be reused by calling execute() again, right?

Even this works, if it is performance-wise not optimal, please give me a
short example of how to use CriticalSection for this purpose.

Thanks a lot.

Xiangrong
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] PostMessage return value

2014-09-15 Thread Xiangrong Fang
2014-09-15 20:34 GMT+08:00 Sven Barth :

> If you want to use a separate thread ("dispatcher") for enqueueing new
> work you should create an event that you pass to this thread and the worker
> threads. The dispatcher waits on the event and the worker threads will
> signal the event once they are done. Of course you'll likely also signal
> the event when new work items are queued that need to be dispatched.
>
In Michael's previous email, I understand that using PostMessage and
QueueAsyncCall will does the same thing.

How do I use Event to achieve the same? It seems that I can have N threads
"listen" to the same event, but cannot have the main thread to "listen" to
N different events?

Anyway, if I use Event I'll do some more reading of the document. For now,
I would like to know, performance-wise, which way is better? Using
QueueAsyncCall/PostMessage or RTLEvent*?
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] PostMessage return value

2014-09-15 Thread Xiangrong Fang
2014-09-15 17:23 GMT+08:00 Michael Schnell :

>
> In that case I definitely would use Application.QueuAsyncCall.
>

If I understand correct, from this page:

http://wiki.freepascal.org/Asynchronous_Calls

QueueAsyncCall is, like what its name suggest, doing this in asynchronous
favor -- it execute queued method in the next message loop (while
Application.ProcessMessages takes place, right?).

But what I need PostMessage for is to notify main thread (or another
thread) that a worker thread finished its job, so that the thread manager
can start a new thread to do the remaining work.

Anyway, is PostMessage considered "deprecated" or "shall be used on windows
only"?   Is there a better way to do what I want?

Thanks,
Xiangrong
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] PostMessage return value

2014-09-15 Thread Xiangrong Fang
2014-09-15 17:12 GMT+08:00 Michael Schnell :

>
> For better clearness, flexibility and portability I would use
> Application.QueueAsyncCall instead (Or TThread.Queue, if you are on the svn
> Version of fpc and would like to do it Delphi-compatible).
>

​I would like to use the most clear, simple FPC way of inter-thread​
  c
​ommunication / locking of shared resources. I DO need cross platform
(linux/windows), but I do NOT want Delphi compatibility, my app only
compiles with FPC/Lazarus :-)

Finally, I prefer to use the latest GENERALLY-AVAIABLE version of FPC,
which is 2.6.4 now, to save me trouble to setup development version of FPC
on any PC I would need to run FPC :-)

Any more hint please? Thanks a lot!

Xiangrong​
​
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] PostMessage return value

2014-09-13 Thread Xiangrong Fang
Hi All,

I try to use PostMessage for inter-thread communication.

After reading the wiki and source code, I found that:

1) PostMessage is defined in winapih.inc, altough I confirmed using a
simple test program that it also work under linux.

2) In the document it is not mentioned when PostMessage will return false?
 In practice, is it necessary to check return value of PostMessage?

Thanks!
Shannon
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Cannot compile EpikTimer

2014-09-02 Thread Xiangrong Fang
Thanks, this worked.  I added unit Linux in here:

{$IFDEF Windows}
  Windows, MMSystem,
{$ELSE}
  unix, unixutil, baseunix, *Linux*,
{$ENDIF}

Should this be considered a minor bug in epiktimer's platform dependant
code?

Xiangrong


2014-09-02 22:28 GMT+08:00 Mattias Gaertner :

> On Tue, 2 Sep 2014 22:18:38 +0800
> Xiangrong Fang  wrote:
>
> > Hi All,
> >
> > While trying to install epiktimer following this wiki page:
> >
> > http://wiki.lazarus.freepascal.org/EpikTimer
> >
> > I got this error:
> >
> > /home/xrfang/git/epiktimer/epiktimer.pas(403,29) Error: Identifier not
> > found "clock_gettime"
>
> clock_gettime is defined in unit Linux.
>
> > I am running Lazarus 1.2.4/FPC2.6.2 on Ubuntu 14.10 64bit.
>
> Mattias
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Cannot compile EpikTimer

2014-09-02 Thread Xiangrong Fang
Hi All,

While trying to install epiktimer following this wiki page:

http://wiki.lazarus.freepascal.org/EpikTimer

I got this error:

/home/xrfang/git/epiktimer/epiktimer.pas(403,29) Error: Identifier not
found "clock_gettime"

I am running Lazarus 1.2.4/FPC2.6.2 on Ubuntu 14.10 64bit.

Any ideas?

Thanks a lot.

Xiangrong
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] use of graphics unit on command line

2014-04-23 Thread Xiangrong Fang
Hi All,

I have a class which uses Graphics unit.  Now I would like to do some test
of this class on command line, which does NOT require graphics support.

That is, suppose my class looks like this:

TMyClass
public
  procedure Generate;  //does NOT use graphics
  procedure Paint; //uses graphics
end;

now I want to test the Generate method. I write a new program like this:

program test;
{$mode objfpc}{$H+}
uses myclass;
begin
end.

The compiler complains that Graphics unit cannot be found.

How can I do such test with just vi and fpc on command line?

Thanks!

Xiangrong
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Shared project configuration

2014-03-25 Thread Xiangrong Fang
Hi Mattias,

If I understood correctly, this method is binding the template to your IDE,
not your project.

In another word, if I create a project and add such a project.ini file in
the project, push it to github. You pull this project, and before you can
use the templetate, you must install my template "separately" (not by just
open the project.ini via lazarus), AND, after install the template you can
use the template OUTSIDE of the project context.  i.e. the template become
somewhat "standard", e.g. "Lazarus Project for Android" might be a custom
template?

What I want is not like this, but just to configure related projects to use
common units and output there executables in common directory.

Thanks,
Xiangrong





2014-03-25 17:11 GMT+08:00 Mattias Gaertner :

> On Tue, 25 Mar 2014 15:53:37 +0800
> Xiangrong Fang  wrote:
>
> > Hi All,
> >
> > Is it possible for lazarus to use "shared project configurations"? The
> > scenario is:
> >
> > 1. I have a project layout as below:
> >
> > 
> >   
> > 
> > 
> >   
> >   
> >
> > The core units I am writing will be put into //, while
> >  sub-dir will contain demo project I use to test/debug the units.
> >
> > At present, I will have to configure any new project to let it look for
> > units under //.
> >
> > It will be useful to have a "project group configuration", such as
> > "projects.prg", which can be opened by lazarus to create a shared
> > configuration, and from that lazrus session, all new project I create
> will
> > by default "inherit" environment settings in the "project group" file
> > (which can be customized individually, of course).
> >
> > Another important reason to have such file is that I want to add it to
> > version control system.
> >
> > Is that possible?
>
> Yes.
> You can save the project options (including compiler options,
> excluding files) as a default:
>
> http://wiki.lazarus.freepascal.org/IDE_Window:_Project_Options#Use_these_settings_as_default_for_new_projects
>
> And you can create new project templates with files:
> http://wiki.lazarus.freepascal.org/Project_Templates
>
> And finally you can write an IDE addon to register project types, with
> their own setup dialogs, bells and whistles.
>
> Mattias
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Shared project configuration

2014-03-25 Thread Xiangrong Fang
Hi All,

Is it possible for lazarus to use "shared project configurations"? The
scenario is:

1. I have a project layout as below:


  


  
  

The core units I am writing will be put into //, while
 sub-dir will contain demo project I use to test/debug the units.

At present, I will have to configure any new project to let it look for
units under //.

It will be useful to have a "project group configuration", such as
"projects.prg", which can be opened by lazarus to create a shared
configuration, and from that lazrus session, all new project I create will
by default "inherit" environment settings in the "project group" file
(which can be customized individually, of course).

Another important reason to have such file is that I want to add it to
version control system.

Is that possible?

Xiangrong
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Getting help for a type if its unit is not in uses

2014-02-05 Thread Xiangrong Fang
This is a great feature suggestion. If implemented I think it should also
work with constants. For example, it cost me some 10+ minutes to figure out
VK_ESCAPE is defined in LCLTypes.

Thanks!


2014-02-05 Sven Barth :

> Hello together!
>
> On the German Delphi-Forum Delphi-PRAXiS there was the question in which
> unit the type TObjectList resided in Lazarus. Besides the obvious answer
> "contnrs" there was also the suggestion to use F1 on the TObjectList
> identifier to let the help find it for you. (For those that can read
> German, here is the thread: http://www.delphipraxis.net/
> 178892-lazarus-kennt-keine-tobjectlist.html )
>
> Now the problem is that this won't work in Lazarus which will return a
> error message "Hilfeschlüsselwort "FPCKeyword_TObjectList" nciht[sic!]
> gefunden." ("Help keyword "FPCKeyword_TObjectList" not found") [plus
> another, in my opinion needless, error message afterwards with (in my case)
> "No help found for "project1.lpr" at (13,16)"] and the user is none the
> wiser... This is at least the case in 1.0.12 on win64, I didn't check for
> any changes here in 1.2/1.3...
>
> Are there any ideas for improving this situation for people that know that
> there is an identifier in the RTL, FCL, whatever, but don't know which unit
> it resides in? E.g. Lazarus did scan the FPC sources, couldn't it keep an
> identifier->unit index? Also could the error message be improved a bit?
> E.g. kick out that second error and use "TObjectList" instead of
> "FPCKeyword_TObjectList" in the error message?
>
> Regards,
> Sven
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus scattered windows

2013-09-02 Thread Xiangrong Fang
Hi Mattias,

Bug report here: http://bugs.freepascal.org/view.php?id=24942

It happens in the case if I want to share the space for Object Inspector
and Code Explorer using "Tab" style...  See attachment in that bug report.

Thanks.



2013/9/2 Mattias Gaertner 

>
> > Dmitry Boyarintsev  hat am 2. September 2013
> um
> > 16:41 geschrieben:
> >
> >  Try "Manual Docker"<
> http://wiki.freepascal.org/index.php?title=Manual_Docker>
> >  it does save, though there's not much save :)
> >
> >
> >  On Mon, Sep 2, 2013 at 8:27 AM, Xiangrong Fang  ><mailto:xrf...@gmail.com> > wrote:
> >> >2013/9/2 Mattias Gaertner  ><mailto:nc-gaert...@netcologne.de> >
> > >  > > >
> > > >
> > > >  > Xiangrong Fang < xrf...@gmail.com <mailto:xrf...@gmail.com>
> > hat
> > > >am 2. September 2013 um 12:08
> > > >  > geschrieben:
> > > >  >
> > > >  >  You may try anchordocking, although that also has some bugs,
> but
> > > >are small
> > > >  >ones, (e.g. window layout cannot be saved).
> > > >  Tools / Save window layout as default.
> > > >> >
> > >This does NOT work, that's why I say it's a bug.
> >[...]
>
> It works here.
> Have you created a bug report?
>
> Mattias
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus scattered windows

2013-09-02 Thread Xiangrong Fang
2013/9/2 William Oliveira Ferreira 

> Can be saved *, but manually and, if you wanna save to a backup file,
> first, create a blank text file then overwrite it.
>
> * At least, the last version i've used on linux (1.0.2)
>
>
Some can be saved, but some cannot.  For example, I try to open "Code
Explorer", but next time I launch lazarus, it is not there. No matter if I
save the layout manually or not.
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus scattered windows

2013-09-02 Thread Xiangrong Fang
2013/9/2 Mattias Gaertner 

>
>
> > Xiangrong Fang  hat am 2. September 2013 um 12:08
> > geschrieben:
> >
> >  You may try anchordocking, although that also has some bugs, but are
> small
> >ones, (e.g. window layout cannot be saved).
>
> Tools / Save window layout as default.
>

This does NOT work, that's why I say it's a bug.
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus scattered windows

2013-09-02 Thread Xiangrong Fang
You may try anchordocking, although that also has some bugs, but are small
ones, (e.g. window layout cannot be saved).



2013/9/2 Michael Van Canneyt 

>
>
> On Mon, 2 Sep 2013, Martin wrote:
>
>  On 31/08/2013 17:13, Jürgen Hestermann wrote:
>>
>>> I am working with Windows XP and
>>> Lazarus is driving me nuts with its multiple window interface.
>>>
>>> Very often, when I use Alt+TAB to switch back to Lazarus I only see
>>> the source editor but none of the other windows (object inspector,
>>> message window, Lazarus main window, etc.).
>>>
>>
>> So how exactly do you not see the other windows? Or more to the point:
>> Why?
>>
>> - Was Lazarus minimized before, and only one Window (e.g. SourceEdit was
>> restored)?
>> - Were the windows hidden behind other apps, and are still (so they were
>> not brought to foreground?
>> - Or ?
>>
>> About hidden windows:  Take note, which window was active before you
>> switched away from the IDE. Is there a pattern?
>> e.g for me, using the mouse, not tab:
>> - if I click the main-IDE bar, all windows come to foreground.
>>
>
> On Linux, kubuntu, kwin WM, this is definitely not the case. This is by
> far the most annoying 'bug' in Lazarus on Linux.
>
> Something one learns to live with :)
>
> Michael.
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TTreeView, string and SIGSEGV

2013-08-26 Thread Xiangrong Fang
Ok, that's reasonable, however:

1) If I use Move() is there a "manual" way to increate the string ref count?

2) why the error is gone if I change this line:

prev := tv.Items.InsertObjectBehind(prev, p^.title, p);

to this:

prev := tv.Items.InsertObjectBehind(prev, 'Node #' + IntToStr(i), p);

3) Why this error does not happen on node #0 and #3, but only node #1 and
#2?

4) Why it behaves different on Windows and Linux?

Thanks!


2013/8/24 Martin 

> On 23/08/2013 16:13, Xiangrong Fang wrote:
>
>> Hi All,
>>
>> I encountered a strange SIGSEGV with the attached program.  To reproduce
>> the problem:
>>
>> 1) compile and run it.
>> 2) select "Node #2"
>> 3) click "Test" button, it will insert a node before the selected Node
>> 4) close the program
>>
>> There will be a SIGSEGV at the end of OnDestroy method.
>>
>> This problem is reproducible under Linux amd64 and Wine and Win7 (32bit).
>> A strange thing is that on Linux or Wine, this error only occur on Node #1
>> and Node #2, but on Windows, it only occur on Node #2 and Node #3.
>>
>> Also, if you swap either of the 2 commented statements, this error is
>> gone.
>>
>> I suspect this is caused by the AnsiString manager.  Could anyone explain
>> why, or is this a bug?
>>
>
> Only had a quick look, please veryfy
>
>  Move(tv.Selected.Data^, p^, SizeOf(TNode));
>   tv.Items.InsertObject(tv.**Selected, 'New Node', p);
>
>
> Move makes a copy of the node, including a copy of the ansistring (that is
> the pointer-part) in the node.
> so now you have 2 strings, referring the same string data, but you never
> increased the ref count.
>
>
>
>
> --
> __**_
> Lazarus mailing list
> Lazarus@lists.lazarus.**freepascal.org
> http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] TTreeView, string and SIGSEGV

2013-08-23 Thread Xiangrong Fang
Hi All,

I encountered a strange SIGSEGV with the attached program.  To reproduce
the problem:

1) compile and run it.
2) select "Node #2"
3) click "Test" button, it will insert a node before the selected Node
4) close the program

There will be a SIGSEGV at the end of OnDestroy method.

This problem is reproducible under Linux amd64 and Wine and Win7 (32bit). A
strange thing is that on Linux or Wine, this error only occur on Node #1
and Node #2, but on Windows, it only occur on Node #2 and Node #3.

Also, if you swap either of the 2 commented statements, this error is gone.

I suspect this is caused by the AnsiString manager.  Could anyone explain
why, or is this a bug?

Thanks a lot.


tree.tar.gz
Description: GNU Zip compressed data
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] IDE: ignore exception if they are caught

2013-08-21 Thread Xiangrong Fang
Hi All,

I have the following code:

try
stream.ReadBuffer(buffer, length);
except
//handle exceptions...
end;

Is it possible to configure lazarus to ignore EStreamError in such case? I
mean I do NOT want to ignore all such exceptions, only those that are
already caught by my code.

Thanks,
Xiangrong
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] UTF8 string handling problem under linux

2013-08-14 Thread Xiangrong Fang
To help reproduce the problem, I altered the program a bit so that it does
not look for a folder containing CJK path.  To reproduce the problem:

1) compile and run this program under Linux (I am running Ubuntu 13.04
amd64).
2) Click the "Write" button and choose the included "test.txt" file.
3) Click the "Read" button, the program will crash.

Note: the test.txt file contains two lines, the program only read the first
line, if that line contains CJK, it will crash.

Thanks,
Shannon



2013/8/14 Xiangrong Fang 

> Hi All,
>
> Could anyone take a look at the problem?  I would like to confirm if this
> is my problem or a bug in lazarus / fpc.
>
> Thanks,
> Shannon
>
>
> 2013/8/12 Xiangrong Fang 
>
>> There is no backtrace at all, the only info I get when starting from
>> command line is:
>>
>> xrfang@fxrmm:~/Desktop/testutf8$ ./project1
>> TApplication.HandleException Access violation
>>   Stack trace:
>>   $7F2ACBF9DBD0
>>
>>
>> Please provide a backtrace.
>>
>>> What is r?
>>>
>>
>> r is a TRegistry object, please see attached source code.
>>
>>
>>> What compiler version?
>>>
>>
>> FPC 2.6.2, Lazarus 1.0.10
>>
>> I suspect this is a bug in related library code, because even if the
>> result is not correct, it should not crash.  Note that this error ONLY
>> occur when I choose a directory with CJK character in its path.
>>
>
>


testutf8.tar.gz
Description: GNU Zip compressed data
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] UTF8 string handling problem under linux

2013-08-14 Thread Xiangrong Fang
Hi All,

Could anyone take a look at the problem?  I would like to confirm if this
is my problem or a bug in lazarus / fpc.

Thanks,
Shannon


2013/8/12 Xiangrong Fang 

> There is no backtrace at all, the only info I get when starting from
> command line is:
>
> xrfang@fxrmm:~/Desktop/testutf8$ ./project1
> TApplication.HandleException Access violation
>   Stack trace:
>   $7F2ACBF9DBD0
>
>
> Please provide a backtrace.
>
>> What is r?
>>
>
> r is a TRegistry object, please see attached source code.
>
>
>> What compiler version?
>>
>
> FPC 2.6.2, Lazarus 1.0.10
>
> I suspect this is a bug in related library code, because even if the
> result is not correct, it should not crash.  Note that this error ONLY
> occur when I choose a directory with CJK character in its path.
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] UTF8 string handling problem under linux

2013-08-11 Thread Xiangrong Fang
btw, the problem occur if the input string is CJK.


2013/8/11 Xiangrong Fang 

> Hi All,
>
> I have the following program:
>
> ===
> procedure TForm1.Button1Click(Sender: TObject);
> begin
>   if sd.Execute then begin
> if r.OpenKey('test_utf8', True) then begin
> //  r.WriteString('path', UTF8ToSys(sd.FileName));
>   r.WriteString('path', sd.FileName);
>   r.CloseKey;
> end;
>   end;
> end;
>
> procedure TForm1.Button2Click(Sender: TObject);
> begin
>   if r.OpenKey('test_utf8', False) then begin
> //ShowMessage('path=' + SysToUTF8(r.ReadString('path')));
> ShowMessage('path=' + r.ReadString('path'));
> r.CloseKey;
>   end;
> end;
> 
>
> It runs OK under windows whether I use SysToUTF8 or not, but on Linux, it
> crashes (SIGSEGV) on the line with r.ReadString.
>
> I wonder what is the correct way to write a program that compile and run
> well under both Windows and Linux?
>
> Thanks,
> Shannon
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] UTF8 string handling problem under linux

2013-08-10 Thread Xiangrong Fang
Hi All,

I have the following program:

===
procedure TForm1.Button1Click(Sender: TObject);
begin
  if sd.Execute then begin
if r.OpenKey('test_utf8', True) then begin
//  r.WriteString('path', UTF8ToSys(sd.FileName));
  r.WriteString('path', sd.FileName);
  r.CloseKey;
end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if r.OpenKey('test_utf8', False) then begin
//ShowMessage('path=' + SysToUTF8(r.ReadString('path')));
ShowMessage('path=' + r.ReadString('path'));
r.CloseKey;
  end;
end;


It runs OK under windows whether I use SysToUTF8 or not, but on Linux, it
crashes (SIGSEGV) on the line with r.ReadString.

I wonder what is the correct way to write a program that compile and run
well under both Windows and Linux?

Thanks,
Shannon
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] hint on unused private method

2013-04-02 Thread Xiangrong Fang
Hi,

Are there any compiler switch so that lazarus can emit hint on unused
private method?

Thanks.
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] embed git version info

2013-03-28 Thread Xiangrong Fang
> I don't think that counts as "doing all the work for the OP" since he's
still got to figure
> out why it works :-)

I may leave some of you a wrong impression that I need spoon-feeding.  Let
me explain what I mean clearly:

While using {$I %DATE%}, I can write:

WriteLn('COMPILED: ' + {$I %DATE%});

i.e. the $I above returned a string without trying to parse it.  But with
{$I revision.inc} the file is parsed!   I just realized this after my first
reply to Graeme.   After think about the logic, I think this makes sense.
However, before I searched the forum for this problem, I didn't realize $I
has such usage (I used to use that for $I- or $I+).

I am a programmer, but I only write apps, not compiler or OS related stuff.
So sometime I may seem naive to "hardcore" or "real" programmers. Just like
I asked why SIGFPE happend on random places.   I don't think answer such
questions are spoon-feeding, just like the sigfpe question.

Sometime I have other considerations as to what is worth to do, e.g.  after
I remembered I have to compile my program under windows, I hesitated
whether I need to embed git rev into my program, because I don't want to
install git on my windows virtual machine, not that I ask step by step help
for how to do it, or write the script.
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] embed git version info

2013-03-28 Thread Xiangrong Fang
>
> What about the following...
>>
>>   const
>> cGitRevision =  + {$revision.inc} + ;
>>
> That should work :)
>

That does not work.
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] embed git version info

2013-03-28 Thread Xiangrong Fang
>
> My first reply suggested that, but Xiangrong didn't like the idea of
> platform specific scripts.
>

I can use InstantFPC to write platform independent script.
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] embed git version info

2013-03-27 Thread Xiangrong Fang
2013/3/27 Lukasz Sokol 

> On 27/03/2013 14:18, Xiangrong Fang wrote:
> > > How can I embed git version info AUTOMATICALLY while I compile my
> program
> >
> > > in lazarus, just like {$I %DATE%} ?
> >
> > Use a pre-compile script (Project Options|Compiler
> > Options|Compilation|Execute Before) in combination with a include
> file.
>

I thought {$I revision.inc} is similar as {$I %DAT%}, but apparently they
have different semantic.
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] embed git version info

2013-03-27 Thread Xiangrong Fang
> How can I embed git version info AUTOMATICALLY while I compile my
program

> > in lazarus, just like {$I %DATE%} ?
>
> Use a pre-compile script (Project Options|Compiler
> Options|Compilation|Execute Before) in combination with a include file.
>

Thanks.

I realized that this may not work for me. Because I need to compile the
project under both Linux and Windows, and then I need 2 scripts in the same
place :-(

Anyway, I tested with the simplest pre-build script:

git describe --always > REVISION.INC


Then in my program I added:

msgs.Lines.Add('GIT HASH: ' + {$I REVISION.INC});

Unfortunately, it does not compile, the error I got is:

unit1.pas(831,50) Error: Identifier not found "c25d546"

It seems that this directive does not load the include file as simple
string??
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] embed git version info

2013-03-26 Thread Xiangrong Fang
Hi,

How can I embed git version info AUTOMATICALLY while I compile my program
in lazarus, just like {$I %DATE%} ?

Thanks.
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] IUnknown and reference counting

2013-03-20 Thread Xiangrong Fang
As a matter of fact, this is what confused me the most.  In my previous
experience, e.g. with java or php, I don't care about COM or CORBA,
interface to me is just another way to implement abstract method for
languages that do not support multiple inheritance. Isn't that the case?

The reason I asked the question initially was I try to implement Enumerator
for my TTreap class so that I can use it in for... in loop.To do this,
can I just implement the GetEnumerator method, or I have to define the
class as this:

generic TTreap = class(IEnumerable);

In another word, if I do not declare that the class implements IEnumerable,
but just add the required method, will the language detect this and make my
class enumerable?


2013/3/20 Graeme Geldenhuys 

> Hi,
>
> Dodi covered it all pretty much...
>
> On 2013-03-20 13:38, Xiangrong Fang wrote:
> >
> > So, what is the purpose of this UUID and the method provided by
> > TInterfacedObject?
>
> Only needed if you are doing COM programming under Windows. For the rest
> of the times you don't need it.
>
> Also note that sometimes it is beneficial having interface support, but
> without reference counting. In that case you can use CORBA-style
> interfaces.
>
> Simply add the following to your unit..
>
> {$mode objfpc}{$H+}
> {$interfaces corba} // <<--   New line
>
> type
>   ITestInterface = interface
> [STestInterface]
> procedure DoSomething;
> procedure DoItAll;
>   end;
>
>
> Now 'interface' in the type declaration will not be a IUnknown or
> IInterface descendant. Thus no need to use TInterfacedObject as a base
> class, TObject will suffice. I tend to use CORBA-style interfaces much
> more in my applications - it allows me to easily add interface support
> to any of my existing classes.
>
> I also believe that you can mix COM and CORBA style interfaces in your
> application, but that is probably not a good idea. Best to avoid that.
>
>
>
> Regards,
>   - Graeme -
>
> --
> fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
> http://fpgui.sourceforge.net/
>
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] IUnknown and reference counting

2013-03-20 Thread Xiangrong Fang
OK, What confused me is the description found in FPC manual saying:

TInterfacedObject is a descendent of
TObject<http://www.freepascal.org/docs-html/rtl/system/tobject.html>which
implements the
IUnknown 
<http://www.freepascal.org/docs-html/rtl/system/iunknown.html>interface.
It can be used as a base class for all classes which need
reference counting.
in another word, reference counting is a feature of TInterfacedObject, or
the AfterConstruction/BeforeDestruction methods??  it sounds like
non-descedants of TInterfacedObject are not reference counted??

2013/3/20 Hans-Peter Diettrich 

> Xiangrong Fang schrieb:
>
>  Hi,
>>
>> I am reading this:
>>
>> http://wiki.freepascal.org/**How_To_Use_Interfaces<http://wiki.freepascal.org/How_To_Use_Interfaces>
>>
>> And wondering what's the *purpose* of "reference counting"?
>>
>
> Delphi (and FPC) implements garbage collection by reference counting. It's
> used in all dynamic (managed) datatypes, like arrays, interfaces,
> AnsiStrings...
>
>
>  While I use interface before in delphi and java, I didn't notice that I
>> need a UUID for interface. I had an impression that it has something to do
>> with COM?
>>
>
> Right, an UUID/GUID for interfaces is Windows COM specific.
>
>
>  So, what is the purpose of this UUID and the method provided by
>> TInterfacedObject?
>>
>
> The GUID allows to look up the interface definition when a type library
> (*.TLB) exists (on a Windows platform).
>
> DoDi
>
>
> --
> __**_
> Lazarus mailing list
> Lazarus@lists.lazarus.**freepascal.org
> http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] IUnknown and reference counting

2013-03-20 Thread Xiangrong Fang
Hi,

I am reading this:

http://wiki.freepascal.org/How_To_Use_Interfaces

And wondering what's the *purpose* of "reference counting"?  While I use
interface before in delphi and java, I didn't notice that I need a UUID for
interface. I had an impression that it has something to do with COM?

So, what is the purpose of this UUID and the method provided by
TInterfacedObject?

Thanks
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] OnAdvancedCustomDrawItem

2013-03-14 Thread Xiangrong Fang
I try to change the checkbox of listview with my own image, and found this:

http://delphi.about.com/od/delphitips2008/qt/lv_checkbox_bmp.htm

But it does not work, although the event handler is indeed called.  What
could be wrong?

Thanks!
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] IDE autocomplete nuisance

2013-03-14 Thread Xiangrong Fang
No:

> Check "Insert Space in FRONT of Symbol"
>

That's the effect I want. thanks.
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] IDE: debug watch

2013-03-14 Thread Xiangrong Fang
Hi,

While single-stepping. I would like to check some data with the
"Evaluate/Modify" tool, for example view the count of a stringlist, I get:

Type TSTRINGLIST = class  has no component named COUNT.

As a matter of fact, I get this kind of thing with most variables, except
simple stuff like integer and string.  Why, and how do I view property of
an object?

Thanks
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] IDE autocomplete nuisance

2013-03-14 Thread Xiangrong Fang
Hi All,

While I use auto complete of a property, the IDE inserts ":=" for me
automatically, this is good, but how can I make it auto insert a SPACE
before the colon so that I don't need to get back and insert it myself
everytime?

Thanks
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] XML Support in Lazarus

2013-03-11 Thread Xiangrong Fang
Hi,

I am reading this: http://wiki.freepascal.org/XML_Tutorial   It seems quite
old (2005?)I wonder if the status quo is still same, especially that
the FCL units still does not support UTF8 encoding?

Thanks,
Shannon
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] TextRect problem and TDisplayCode

2013-03-08 Thread Xiangrong Fang
Hi All,

I try to do some customization in TListView.OnCustomDrawItem:

r := Item.DisplayRect(drBounds);
TextOut(r.Left, r.Top, 'Hello');  <-- this worked
TextRect(r, 0, 0, 'Hello');   <-- this does not work

Why?

Another question which I cannot google any answer is, what's the meaning of
TDisplayCode? I don't want its values which is obvious, but the meaning of
each value, e.g. drBounds, drLabels etc. Not documented anywhere...

Thanks,
Shannon
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] What's "External: SIGFPE"?

2013-03-07 Thread Xiangrong Fang
2013/3/7 leledumbo 


> Because setting the mask means telling the processor to generate (or not to
> generate? I forgot) SIGFPE for the given operations. e.g. exZeroDivide may
> trigger SIGFPE if there's a division by zero with floating point operation.
> How to trace? You already get it, the program will report the line that
> causes it, you can directly go to the respective line to see what happens.
> But this requires that the code lies in the program space (not in external
> library) and the code is compiled with runtime error backtrace (-gl).
> Otherwise, the program can only report as deep as it can find.
>

I don't understand:

1) even if I set the masks, why an empty LCL application generate SIGFPE?
It means that somewhere GTK or whatever library *indeed* do things like
1/0, only that they are normally hidden/not reported?

2) I already found the problem in my code which is a like look like:

*if tbLog.Down then Y := exp(Y);*

And Y is a big number e.g. 2500, which caused floating point overflow.
The problem was that the number itself should be Log()ed, so that exp()
only restore its original value.   That was my bug, but the weird thing is
that SIGFPE is generated in unit LCLType on the line that set font height,
which is very innocent, and after I commented out the font.Height
operation, the SIGFPE slipped to somewhere else, but NEVER on the line that
generated it!

Could you explain why? and how to locate where the SIGFPE occurred?

Thanks!
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] "nested" packed record?

2013-03-06 Thread Xiangrong Fang
Hello,

Is the "packed" keyword effective for nested records? i.e.

TMyRecord = packed record
Component: *packed* record
Field: Integer;
... ...
end;
... ...
end;

Does Component have to be packed to ensure entire record is packed, or,
"packed" is only required for the outmost record keyword?

Thanks,
Shannon
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Change font of a TPaintBox

2013-03-06 Thread Xiangrong Fang
Hi All,

I am writing some text on a TPaintBox.Canvas.  I found that if I set
canvas.font on FormShow, it does NOT work, I have to set font inside the
OnPaint procedure of the canvas. Why the font information is not persisted
when it is set?

Thanks
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] What's "External: SIGFPE"?

2013-03-06 Thread Xiangrong Fang
Hi All,

I am making a charting program and encountered very weird error.   The
exception raised is: 'External: SIGFPE'. In file 'lcltype.pp' at line
3009.   On that line is the MulDiv() function, and the operation I am doing
is just assigning font height.   I then remembered the question i asked
days ago about 1/0 and Ln(0).  Sven suggested to use SetExceptionMask.

I tried this in my FormCreate:

  SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow,
exUnderflow]);

Now the program crashes every time it start.   I also tested to put the
above line on an empty project, same error happened in gtk2winapi.inc!

Could anyone explain what's SIGFPE? Why there is a SetExceptionMask? Why a
normal empty form application will generate SIGFPE with these masks, and
how to trace down to the cause of this error?

Thanks a lot!
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Why Ln(0) and 1/0 does not trigger Exception?

2013-03-04 Thread Xiangrong Fang
X := 0; Ln(X) seems to generated an exception without need to adjust
exception mask. The reason I ask is that I get a strange crash while doing
my charting program, I just suspected the reason being an exception is
slipped through without being caught.

As this happened outside of IDE, I don't know the exact reason. I will do a
screenshot and ask again.

Thanks.

2013/3/5 Sven Barth 

> Am 04.03.2013 16:05, schrieb Xiangrong Fang:
>
>  As title.  My question is not just "it is a language construct", but
>> "WHY".  What's the benefit of doing so?
>>
> I already wrote this in the other thread: if you write "ln(0)" then the
> compiler will hardcode this as "NaN". I don't know what will happen with
> "ln(x)" with "x := 0" though. Maybe you'll need to set the exception mask
> correctly (see here: http://www.freepascal.org/**docs-html/rtl/math/**
> setexceptionmask.html<http://www.freepascal.org/docs-html/rtl/math/setexceptionmask.html>)
>  to get an exception.
>
> Regards,
> Sven
>
>
> --
> __**_
> Lazarus mailing list
> Lazarus@lists.lazarus.**freepascal.org
> http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Why Ln(0) and 1/0 does not trigger Exception?

2013-03-04 Thread Xiangrong Fang
As title.  My question is not just "it is a language construct", but
"WHY".  What's the benefit of doing so?

Thanks.
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] LongString does not work?

2013-03-03 Thread Xiangrong Fang
I was using an INI file, but record make things a lot easier.

2013/3/3 Bart 

> On 3/3/13, Xiangrong Fang  wrote:
>
>
> >   TConfiguration = packed record
> >   DataFolder: array [0..MaxPathLen] of Char;
> >   end;
> >
> > worked.  My save procedure is:
> >
> > function SaveParams(var Buffer; Count: Integer; FileName: string):
> Boolean;
> > var
> >   fs: TFileStream;
> > begin
> >   Result := False;
> >   if not ForceDirectories(ExtractFilePath(FileName)) then Exit;
> >   try
> > fs := TFileStream.Create(FileName, fmCreate);
> > try
> >   fs.Write(Buffer, Count);
> >   Result := True;
> > finally
> >   fs.Free;
> > end;
> >   except
> >   end;
> > end;
> >
> > It is called on the finalization section of config.pas:
> >
> > SaveParams(cfg, SizeOf(cfg), cfn);
> > //cfg is TConfgiruation, cfn is the filename.
> >
>
> Are you only writing strings (and/or integers and/or booleans)  to the
> configuration file?
> If so, wouldn't it be just easier to use a TIniFile for that?
>
> Bart
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] LongString does not work?

2013-03-03 Thread Xiangrong Fang
A (Ansi)string in {$H+} mode is just a pointer (to the characters of the
string). So sizeof(DataFolder)=4 (or 8) in all cases. There is no room for
the string unless

I guess this is the cause, but then there is no need to specify "packed" if
I just use array of char.
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] LongString does not work?

2013-03-03 Thread Xiangrong Fang
Hi Sven,

{$mode objfpc}{$H+}
  TConfiguration = packed record
  DataFolder: string;
  end;

does not work, but:

  TConfiguration = packed record
  DataFolder: array [0..MaxPathLen] of Char;
  end;

worked.  My save procedure is:

function SaveParams(var Buffer; Count: Integer; FileName: string): Boolean;
var
  fs: TFileStream;
begin
  Result := False;
  if not ForceDirectories(ExtractFilePath(FileName)) then Exit;
  try
fs := TFileStream.Create(FileName, fmCreate);
try
  fs.Write(Buffer, Count);
  Result := True;
finally
  fs.Free;
end;
  except
  end;
end;

It is called on the finalization section of config.pas:

SaveParams(cfg, SizeOf(cfg), cfn);
//cfg is TConfgiruation, cfn is the filename.

The symptoms of error are:
1. The DataFolder value is not saved to configuration file, although file
saving seems succeeded.
2. There are weird access violations, e.g. on exiting or on occasions that
I try to manipulate the configuration at runtime (RunError(203) was
reported).

Anything that I did wrong? or, AnsiString is not supported this way anyway?

2013/3/3 Sven Barth 

> On 03.03.2013 10:57, Xiangrong Fang wrote:
>
>> Ok, My purpose is to write the record into stream, so I cannot use
>> variable length. Now I use an array [0..MaxPathLen] of Char.
>>
>
> If you want to write a complete record to stream (and not write it's
> elements manually) you should declare your record as "packed" as only then
> the records are guaranteed to be the same on different plattforms (with the
> exception of different endianess).
>
> E.g.
>
> === code begin ===
>
> type
>   TConfiguration = packed record
> //
>   end;
>
> === code end ===
>
> See also here: http://community.freepascal.**
> org/docs-html/ref/refsu15.html<http://community.freepascal.org/docs-html/ref/refsu15.html>
>
>
> Regards,
> Sven
>
> --
> __**_
> Lazarus mailing list
> Lazarus@lists.lazarus.**freepascal.org
> http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] LongString does not work?

2013-03-03 Thread Xiangrong Fang
Ok, My purpose is to write the record into stream, so I cannot use variable
length. Now I use an array [0..MaxPathLen] of Char.

2013/3/3 Sven Barth 

> On 03.03.2013 09:35, Xiangrong Fang wrote:
>
>> Hi All,
>>
>> This does not work:
>>
>>TConfiguration = record
>>  DataFolder: string[MaxPathLen];
>>end
>>
>> Error: string length must be a value from 1 to 255
>>
>> I already have this on the top of my uinit file: {$mode
>> objfpc}{$H+}{$LONGSTRINGS ON}
>>
>> Working with Lazarus 1.0.6/FPC2.6.0 on Linux 3.5/x86_64
>>
>> Any hint please? Thanks!
>>
>
> The "String[...]" declaration always declares a ShortString and those can
> have only 1 to 255 characters. An AnsiString does not need the "[...]",
> because it has always variable length.
>
> Side note: {$H+} and {$LONGSTRINGS ON} is redundant, both mean the same
> (though {$H+} is more commonly used).
>
> Regards,
> Sven
>
>
> --
> __**_
> Lazarus mailing list
> Lazarus@lists.lazarus.**freepascal.org
> http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] ForceDirectoriesUTF8

2013-03-03 Thread Xiangrong Fang
> If your program has to work now or with older compilers/libraries you
> have to use the *UTF8 functions.
>
> But the problem is, my program works on both Linux and Windows 7 using
ForceDirectories (NOT the UTF8 version), and btw, I am running Chinese
Version of Windows 7.

Could you please tell me what error could happen if I do not use the UTF8
version?


> Mattias
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] LongString does not work?

2013-03-03 Thread Xiangrong Fang
Hi All,

This does not work:

  TConfiguration = record
DataFolder: string[MaxPathLen];
  end

Error: string length must be a value from 1 to 255

I already have this on the top of my uinit file: {$mode
objfpc}{$H+}{$LONGSTRINGS ON}

Working with Lazarus 1.0.6/FPC2.6.0 on Linux 3.5/x86_64

Any hint please? Thanks!
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] "buffer" and string

2013-03-02 Thread Xiangrong Fang
If a buffer expect the first "element", and count is the number of elements
to write, then what is the unit size of that element? is it always "byte"?

2013/3/3 leledumbo 

> > My question is, why the above code with string works sometime, but not
> alwasy fail?
>
> TStream.Write expects a buffer, typically the first element of an item (NOT
> a pointer to it) and the length (number of elements after first one).
>
> > fs.Write(s, Length(s));
>
> Here you try to give the WHOLE string, which is variable depending on the
> string type. It could be plain array for ShortString, but also pointer to a
> dynamically allocated structure for other strings. For ShortStrings,
> however, the above code will have the string length (if I'm not mistaken)
> before the first character in the written file.
>
> To do it correctly without converting to PChar is to give the first
> element:
>
> fs.Write(s[1], Length(s));
>
> > What is the internal structure of string and variable array (i.e. array
> of
> > something)?
>
> Explained in docs:
> - static array:
> http://www.freepascal.org/docs-html/prog/progsu161.html#x204-2170008.2.9
> - dynamic array:
> http://www.freepascal.org/docs-html/prog/progsu162.html#x205-2180008.2.10
> - strings:
> http://www.freepascal.org/docs-html/prog/progsu159.html#x202-2120008.2.7
>
> > What is the difference between @string and @string[1] or @array and
> > @array[0]?
>
> @string means pointer to to the string STRUCTURE, for ShortString, this is
> the same as @string[0] (the length)
> @string[1] means pointer to the first character in the string
> @array means pointer to the array STRUCTURE, for static array, this is the
> same as @array[]
> @array[0] means pointer to the element at index 0
>
>
>
>
>
> --
> View this message in context:
> http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-buffer-and-string-tp4029601p4029603.html
> Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com.
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] "buffer" and string

2013-03-02 Thread Xiangrong Fang
Hi,

I encountered unpredictable behavior with the following code:

var
  fs: TFileStream;
  s: string;
begin
  ... ...
  fs.Write(s, Length(s));
  ... ...
end;

But if I do this, then problem is gone:

var
  fs: TFileStream;
  s: string;
  buf: PChar;
begin
  ... ...
  buf := GetMem(Length(s) + 1);
  StrPCopy(buf, s);
  fs.Write(buf^, Length(s));
  ... ...
end;

My question is, why the above code with string works sometime, but not
alwasy fail? What is the internal structure of string and variable array
(i.e. array of something)?  What is the difference between @string and
@string[1] or @array and @array[0]?

Thanks
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] ForceDirectoriesUTF8

2013-03-02 Thread Xiangrong Fang
> I would think that that depends on where you get the value for
> ForceDirectories(UTF8) from.
> If this vale is obtained from any widget (OpenDialog, TEdit, etc.) the
> encoding of the value is in UTF-8.
> If however you get the value as a commandline parameter, then it is in
> system-encoding if you use ParamStr(), but in UTF-8 if you use
> ParamStrUTF8().

That's what I guessed, so Instead of using UTF8 version I would use this to
ensure cross platform correctness:

Path := SelectDirectoryDialog1.FileName;
ForceDirectories(UTF8Decode(Path));

Right? Yesterday I found in this post (which triggered me to ask the
question initially):

http://lists.lazarus.freepascal.org/pipermail/lazarus/2012-April/073170.html

Such problems may (should) go away with the new Unicode- and AnsiString
types, where AnsiString contains an Encoding field. Then the conversion
between UTF-8 and the system codepage are done automatically, whenever
required, and the xyUTF8 functions can be dropped then.

If so, we shall avoid using **UTF8 functions at all.


2013/3/3 Bart 

> On 3/2/13, Xiangrong Fang  wrote:
>
> > In order to write cross platform programs, shall I use ForceDirectories
> or
> > ForceDirectoriesUTF8?  I would like to:
>
> I would think that that depends on where you get the value for
> ForceDirectories(UTF8) from.
> If this vale is obtained from any widget (OpenDialog, TEdit, etc.) the
> encoding of the value is in UTF-8.
> If however you get the value as a commandline parameter, then it is in
> system-encoding if you use ParamStr(), but in UTF-8 if you use
> ParamStrUTF8().
>
> So you would use:
>
> Path := ParamStr(1);
> ForceDirectories(Path);
>
> or
>
> Path := SelectDirectoryDialog1.FileName;
> ForceDirectoriesUtf8(Path);
>
> You need to be sure which encoding a string has when you pass it on to
> such procedures/functions.
>
> Bart
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] ForceDirectoriesUTF8

2013-03-02 Thread Xiangrong Fang
My program is always in {$mode objfpc}  So string is not a problem, but
shall I use the UTF8 version or not? I remember that Windows is NOT UTF8?

2013/3/2 Sven Barth 

> On 02.03.2013 15:12, Xiangrong Fang wrote:
>
>>   * Avoid using AnsiString or the like (as all my programs use string
>>
>> type, change them all to AnsiString is scaring and I don't know the
>> consequence at all).
>>
>
> Are your programs compiled in either {$mode Delphi} or {$mode
> ObjFPC}{$H+}? If so then "String" = "AnsiString" already... (otherwise
> String is equivalent to ShortString)
>
> Regards,
> Sven
>
> --
> __**_
> Lazarus mailing list
> Lazarus@lists.lazarus.**freepascal.org
> http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] ForceDirectoriesUTF8

2013-03-02 Thread Xiangrong Fang
Hi,

In order to write cross platform programs, shall I use ForceDirectories or
ForceDirectoriesUTF8?  I would like to:

   - Use native charset on the platform (i.e. UTF8 on Linux and whatever
   codepage on Windows)
   - Avoid using AnsiString or the like (as all my programs use string
   type, change them all to AnsiString is scaring and I don't know the
   consequence at all).

Thanks.
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Assignment on exception (was Re: exception handling in constructor)

2013-03-02 Thread Xiangrong Fang
I guess there is really a bug, see the following:
==
  f := 123;
  try
f := ln(0);
  except
  end;
  //WriteLn(f);
  //{
  if f = 123 then
WriteLn('f=123, not modified')
  else
WriteLn('f is modified to:', f);
  //}
===

If I just WriteLn(f), it output Nan, I think there is some magic happening
here.

If I try to use if-then on f, then I get:

An unhandled exception occurred at $0040028C :
EDivByZero : Division by zero
  $0040028C line 18 of project1.lpr


2013/3/2 Michael Van Canneyt 

>
>
> On Sat, 2 Mar 2013, Xiangrong Fang wrote:
>
>  Hi,
>>
>> Could anyone explain this:
>>
>> Number := 123;
>> try
>>   Number := Ln(0);
>> except
>> end;
>> WriteLn(Number);
>>
>> The output is Nan, not 123. i.e. when exception occurs the variable is
>> modified anyway!  So in the example below assigning MyInstance
>> to nil before Create does not help to ensure it is nil if an exception
>> occurs?
>>
>
> It does, you can test that.
>
> I suspect that the case above is an artifact of the FPU error reporting,
> and it should be filed as a bug.
>
> Michael.
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Assignment on exception (was Re: exception handling in constructor)

2013-03-02 Thread Xiangrong Fang
Hi,

Could anyone explain this:

Number := 123;
try
  Number := Ln(0);
except
end;
WriteLn(Number);

The output is *Nan*, not 123. i.e. when exception occurs the variable is
modified anyway!  So in the example below assigning MyInstance to nil
before Create does not help to ensure it is nil if an exception occurs?

Thanks.

2013/3/2 Hans-Peter Diettrich 

> Sven Barth schrieb:
>
>
>  If you want to ensure that MyInstance is Nil you need to do it like this:
>>
>> === code begin ===
>>
>> try
>>   MyInstance := TMyClass.Create('**AnNonExistentFile');
>> except
>>   MyInstance := Nil;
>> end;
>>
>> === code end ===
>>
>
> When an exception occurs in Create, the assignment will never take place.
> That's why MyInstance should be set to Nil *before* calling the
> constructor. This also applies to memory leak protection of multiple
> temporary objects:
>
> inst1 := nil;
> inst2 := nil;
> ...
> try
>   inst1 := T1.Create;
>   inst2 := T2.Create;
>   ...
> finally
>   inst1.Free;
>   inst2.Free;
>   ...
> end;
>
> The Free does no harm, even if the instances never were created, when the
> variables are nil'ed before the try block.
>
> DoDi
>
>
>
> --
> __**_
> Lazarus mailing list
> Lazarus@lists.lazarus.**freepascal.org
> http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] exception handling in constructor

2013-03-01 Thread Xiangrong Fang
Hi there,

If my class constructor looks like this:

constructor TMyClass.Create(fn: string);
begin
  sl := TStringList.Create;
  try
fs := TFileStream.Create(fn, fmOpenRead);
  except
self.Destroy;
  end;
end;

I create the objec like:  MyInstance :=
TMyClass.Create('AnNonExistentFile');  An exception occured, I can ensure
that:

   1. there is no memory leak.
   2. the MyInstance variable is assigned *nil*?

Thanks
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] "global" operator overloading

2013-02-26 Thread Xiangrong Fang
Then, I wish to see 2.8 released :-D

thanks.

2013/2/26 Sven Barth 

> On 26.02.2013 15:30, Xiangrong Fang wrote:
>
>> Hi Sven,
>>
>> My code below:
>>
>> ==**=
>> program project1;
>> {$mode objfpc}{$H+}
>> {$MODESWITCH advancedrecords}
>>
>> uses Classes;
>> type
>>TMyStringList = record
>>  StringList: TStringList;
>>  class operator <(s1, s2: TMyStringList): Boolean;
>>end;
>>
>> class operator TMyStringList.<(s1, s2: TMyStringList): Boolean;
>> begin
>>Result := s1.StringList.Count < s2.StringList.Count;
>> end;
>>
>> begin
>> end.
>> ==**=
>>
>> generated these errors:
>>
>> project1.lpr(9,20) Error: It is not possible to overload this operator.
>> Related overloadable operators (if any) are:
>> project1.lpr(9,21) Error: It is not possible to overload this operator.
>> Related overloadable operators (if any) are:
>> project1.lpr(9,53) Error: Impossible operator overload
>> project1.lpr(12,31) Error: method identifier expected
>> project1.lpr(1,1) Fatal: Compilation aborted
>>
>> I am using Lazarus 1.0.6/FPC2.6.0-6  on Linux Mint 14/x86_64.
>>
>
> Hmm... 2.6.0 seems to indeed have problems there. I did not test 2.6.2 (I
> don't have it installed yet), but 2.7.1 works without problems.
>
>
> Regards,
> Sven
>
>
> --
> __**_
> Lazarus mailing list
> Lazarus@lists.lazarus.**freepascal.org
> http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] "global" operator overloading

2013-02-26 Thread Xiangrong Fang
Hi Sven,

My code below:

===
program project1;
{$mode objfpc}{$H+}
{$MODESWITCH advancedrecords}

uses Classes;
type
  TMyStringList = record
StringList: TStringList;
class operator <(s1, s2: TMyStringList): Boolean;
  end;

class operator TMyStringList.<(s1, s2: TMyStringList): Boolean;
begin
  Result := s1.StringList.Count < s2.StringList.Count;
end;

begin
end.
===

generated these errors:

project1.lpr(9,20) Error: It is not possible to overload this operator.
Related overloadable operators (if any) are:
project1.lpr(9,21) Error: It is not possible to overload this operator.
Related overloadable operators (if any) are:
project1.lpr(9,53) Error: Impossible operator overload
project1.lpr(12,31) Error: method identifier expected
project1.lpr(1,1) Fatal: Compilation aborted

I am using Lazarus 1.0.6/FPC2.6.0-6  on Linux Mint 14/x86_64.

Sincerely,
Shannon



2013/2/26 Sven Barth 

> On 26.02.2013 09:36, Xiangrong Fang wrote:
>
>> Hi Sven,
>>
>> Could you please give a simple example that shows what you said: require
>> that the type with which you specialize is a record. Then a class
>> operator in that record can be defined.
>>
>
> Let's suppose you have the following generic declaration:
>
> === example begin ===
>
> type
>   generic TTreap = class
> // let's assume T1 requires "<"
>   end;
>
> === example end ===
>
> If you use a record to specialize TTreap's T1 parameter then you can do it
> the following way:
>
> === example begin ===
>
> type
>   TMyRecord = record
> // note: in mode objfpc the modeswitch advancedrecords is needed
> class operator < (aLeft, aRight: TMyRecord): Boolean;
>   end;
>
> // implementation:
>
> class operator TMyRecord.<(aLeft, aRight: TMyRecord): Boolean;
> begin
>   // compare aLeft and aRight
> end;
>
> // somewhere else
>
> TTreapTMyRecordLongInt = specialize TTreap;
>
> === example end ===
>
> Now the generic will specialize without problem. If you want to specialize
> other types that don't support class operators then you need to wrap them
> inside a record, e.g.:
>
> === example begin ===
>
> type
>   TRecTStringList = record
> MyStringList: TStringList;
> class operator < (aLeft, aRight: TRecTStringList): Boolean;
>   end;
>
> === example end ===
>
> You can also use visibility modifiers like private or strict private to
> hide the MyStringList field and make it accessible only through properties.
> To simplyfy usage you can also define assignment operators. E.g.:
>
> === example begin ===
>
> type
>   // maybe it will also work with a TStringList if you use TStrings
> instead...
>   TRecTStringList = record
>   private
> fStringList: TStringList;
>   public
> class operator := (aRight: TStringList): TRecTStringList;
> class operator := (aRight: TRecStringList): TStringList;
>   end;
>
> class operator TRecTStringList.:=(aRight: TStringList): TRecTStringList;
> begin
>   Result.fStringList := aRight;
> end;
>
> class operator TRecTStringList.:=(aRight: TRecStringList): TStringList;
> begin
>   Result := aRight.fStringList;
> end;
>
> // somewhere else:
> var
>   sl: TStringList;
>   rec: TRecStringList;
> begin
>   // setup sl
>   rec := sl;
>   // use rec in the tree
>   sl := rec;
> end;
>
> === example end ===
>
> It's not the nicest solution, but currently the only thing you can do.
>
>
> Regards,
> Sven
>
> --
> __**_
> Lazarus mailing list
> Lazarus@lists.lazarus.**freepascal.org
> http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] "global" operator overloading

2013-02-26 Thread Xiangrong Fang
Hi Sven,

Could you please give a simple example that shows what you said: require
that the type with which you specialize is a record. Then a class operator
in that record can be defined.

Thanks

2013/2/26 Sven Barth 

> Am 26.02.2013 08:59 schrieb "xrfang" :
>
> >>
> >> No, it's not a dilemma, but rather a requirement. Before generics
> >> specialization, all required operations for given type must be known.
> This
> >> is because the symbol table when the generics is parsed must be
> >> reconstructed when it gets specialized. Think about declaring usual
> classes
> >> with the generic parameter replaced with actual type. If at that time,
> the
> >> operation < is not yet defined, the code won't compile anyway.
> >
> >
> > It is a pity. I think if fpc supports class operators, maybe this
> problem could be solved by using class helpers (my purpose is that users of
> ttreap class does not have to modify treap.pas) ? Is that possible in
> future FPC?
>
> Helpers have the same problem. For now there is only one solution (as I
> already wrote): require that the type with which you specialize is a
> record. Then a class operator in that record can be defined.
>
> For the future I already have the following longterm plans:
> - add class operator support to class and object
> - allow to specify additional units after "specialize" that will be used
> when specializing (they will be added first, so that the original code is
> not unnecessarily modified)
>
> Regards,
> Sven
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] two questions about generics

2013-02-22 Thread Xiangrong Fang
Thanks Sven.  In the case I use Default() does it mean it always has fixed
defaults with specific types, e.g. 0 for integer '' for string. Or I can
set my own default value?

2013/2/22 Sven Barth 

> On 22.02.2013 04:48, Xiangrong Fang wrote:
>
>> Hi all,
>>
>> I have two questions about generics.  I am writing a two-dimensional
>> table class. Say:
>>
>> type
>>generic TTable = class
>>... ...
>>public
>>  constructor Create(ADefaultValue: TValue);
>>end;
>>
>> My questions are:
>>
>> 1) if I am not writing a generic class I can define default value for
>> the constructor, i.e.
>>
>> constructor Create(ADefaultValue: Double = 0);
>>
>> for generic classes, how can I define a default value?
>>
>
> You can use the new intrinsic Default(TypeName) which is available in FPC
> 2.7.1. Your declaration would look like this:
>
> === snippet begin ===
>
> constructor Create(ADefaultValue: TValue = Default(TValue));
>
> === snippet end ===
>
> You need to pay attention though with what you specialize TTable. You
> can't use a record for example, because records can not have default values
> in parameters (this has nothing to do with generics or the Default()
> intrinsic). Classes and interfaces are ok they as are all primitive types.
>
> As a sidenote: Default() can not only be used in constructor parameter
> lists, but also for normal functions and in normal code. Using it in const
> sections or var sections does not yet work in every case (primitive types
> work, classes, interfaces, records and objects do not).
>
>
>
>> 2) if I cannot define a default value, I hope to do so while
>> specializing it. i.e.
>>
>> type
>>TNumericTable = specialize TTable
>>public
>>  constructor Create(ADefaultValue: Double = 0); override;
>>end;
>>
>> That is, can I "inherit" a generic class while specializing it?
>>
>
> You would need to write it this way:
>
> === code begin ===
>
> type
>   TNumericTable = class(specialize TTable)
>
>   public
> constructor Create(ADefaultValue: Double = 0);
>   end;
>
> constructor TNumericTable.Create(**ADefaultValue: Double);
> begin
>   inherited Create(ADefaultValue);
> end;
>
> === code end ===
>
> Regards,
> Sven
>
> --
> __**_
> Lazarus mailing list
> Lazarus@lists.lazarus.**freepascal.org
> http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] two questions about generics

2013-02-21 Thread Xiangrong Fang
Hi all,

I have two questions about generics.  I am writing a two-dimensional table
class. Say:

type
  generic TTable = class
  ... ...
  public
constructor Create(ADefaultValue: TValue);
  end;

My questions are:

1) if I am not writing a generic class I can define default value for the
constructor, i.e.

constructor Create(ADefaultValue: Double = 0);

for generic classes, how can I define a default value?

2) if I cannot define a default value, I hope to do so while specializing
it. i.e.

type
  TNumericTable = specialize TTable
  public
constructor Create(ADefaultValue: Double = 0); override;
  end;

That is, can I "inherit" a generic class while specializing it?

Thanks,
Shannon
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Check if an abstract method is implemented or not

2013-01-24 Thread Xiangrong Fang
One more report:

I finally decided to use the solution suggested by Fei, i.e. empty method
in base class instead of Abstract method. Becuase comparing address to
@system.AbstractError caused trouble if I put my class into a shared
library.

Thanks.



2013/1/24 Mattias Gaertner 

>
> Xiangrong Fang  hat am 24. Januar 2013 um 14:03
> geschrieben:
>
> > This is a clean solution. And as a matter of fact, the compiler does NOT
> warn
> > me while instantiate class with abstract method.
>
> Normally the compiler warns for each abstract method. For example, this
> creates
> 5 warnings:
>  TStrings.Create;
> If not then please create a bug report.
>
>
> > This is different than Java, in which you must implement all abstract
> method
> > while inherits from an abstract class.
> >
> >  Why I shall not instantiate a sub-class that has not fully implemented
> > abstract methods of its parent class?
>
> Well, you can shoot yourself in the foot. ;)
>
> Mattias
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Check if an abstract method is implemented or not

2013-01-24 Thread Xiangrong Fang
Sorry I overlooked the message. Complie DO emit warnings.

As the use of sub-class is well controlled, I will check in every place the
abstract method is called, so this is ok for me.

Thanks a lot.

2013/1/24 Michael Van Canneyt 

>
>
> On Thu, 24 Jan 2013, Xiangrong Fang wrote:
>
>  This is a clean solution. And as a matter of fact, the compiler does NOT
>> warn me while instantiate class with abstract method.
>>
>
> It definitely does, unless you use a class pointer to do it of course.
>
> In the below example:
>
>   TParentClass = Class of TParent;
>
> Var
>   PC : TParentClass;
>
> begin
>   PC:=TChild;
>   C:=PC.Create;
> end;
>
> You will not get a warning. But if you run the example as I described it,
> you get:
>
> home: >fpc -S2 -vwh te.pp
> te.pp(15,19) Warning: Constructing a class "TChild" with abstract method
> "MyMethod"
> te.pp(5,15) Hint: Found abstract method: procedure MyMethod();
>
>
>   This is different than Java,
>> in which you must implement all abstract method while inherits from an
>> abstract class.
>>
>
>
>> Why I shall not instantiate a sub-class that has not fully implemented
>> abstract methods of its parent class?
>>
>
> Obviously:
> Because then you run the risk that you try to execute a method that is not
> implemented.
>
> Michael.
>
>
>> Thanks!
>> Shannon
>>
>>
>> 2013/1/24 Michael Van Canneyt 
>>
>>
>>   On Thu, 24 Jan 2013, xrfang wrote:
>>
>> Hi All,
>> I wrote a TPainter abstract class, and a TPaintRect class.
>>  In the TPaintRect class I have this code:
>>
>> procedure TPaintRect.OnMouseEnter(**Sender: TObject);
>> var
>>   i: Integer;
>>   p: TPainter;
>> begin
>>   for i := 0 to painters.Count - 1 do begin
>> p := TPainter(painters.Objects[i]);
>> try
>>   p.OnMouseEnter(Sender);
>> except on EAbstractError do ; end;
>>   end;
>>   if Assigned(FOnMouseEnter) then FOnMouseEnter(Sender);
>> end;
>>
>> While running in IDE, the program will crash because
>> OnMouseEnter is abstract.
>>
>> My problems are:
>>
>> 1) As I already wrapped it with try-except, I hope it won't
>> trigger IDE exception. But even I turn off "Notify on Lazarus Exception" in
>> debugger options it
>> still pops up, and the popup said RunError(211), NOT
>> EAbstractError.  The program runs well outside of IDE.
>>
>> 2) Is there a way to detect if an abstract method is
>> implemented or not, without trying to call it and try...except?
>>
>>
>> The following will do it:
>>
>> uses sysutils;
>>
>> Type
>>   TParent = Class
>> Procedure MyMethod; virtual; abstract;
>>   end;
>>
>>   TChild = class(TParent)
>>   end;
>>
>> var
>>   C : TParent;
>>
>> begin
>>   c:=TChild.Create;
>>   If TMethod(@C.MyMethod).Code=**Pointer(@system.AbstractError) then
>> Writeln('Not implemented')
>>   else
>> Writeln('Implemented')
>> end.
>>
>> When run, it will print 'Not implemented'.
>>
>> But you should not instantiate objects with abstract methods to begin
>> with.
>>
>> The compiler warns you if you do.
>> (compile the above program with warnings/hints to see it)
>>
>> Michael.
>> --
>> __**_
>> Lazarus mailing list
>> Lazarus@lists.lazarus.**freepascal.org
>> http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>
>>
>>
>>
>>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Check if an abstract method is implemented or not

2013-01-24 Thread Xiangrong Fang
This is a clean solution. And as a matter of fact, the compiler does NOT
warn me while instantiate class with abstract method.   This is different
than Java, in which you must implement all abstract method while inherits
from an abstract class.

Why I shall not instantiate a sub-class that has not fully implemented
abstract methods of its parent class?

Thanks!
Shannon


2013/1/24 Michael Van Canneyt 

>
>
> On Thu, 24 Jan 2013, xrfang wrote:
>
>  Hi All,
>> I wrote a TPainter abstract class, and a TPaintRect class.  In the
>> TPaintRect class I have this code:
>>
>> procedure TPaintRect.OnMouseEnter(**Sender: TObject);
>> var
>>   i: Integer;
>>   p: TPainter;
>> begin
>>   for i := 0 to painters.Count - 1 do begin
>> p := TPainter(painters.Objects[i]);
>> try
>>   p.OnMouseEnter(Sender);
>> except on EAbstractError do ; end;
>>   end;
>>   if Assigned(FOnMouseEnter) then FOnMouseEnter(Sender);
>> end;
>>
>> While running in IDE, the program will crash because OnMouseEnter is
>> abstract.
>>
>> My problems are:
>>
>> 1) As I already wrapped it with try-except, I hope it won't trigger IDE
>> exception. But even I turn off "Notify on Lazarus Exception" in debugger
>> options it
>> still pops up, and the popup said RunError(211), NOT EAbstractError.  The
>> program runs well outside of IDE.
>>
>> 2) Is there a way to detect if an abstract method is implemented or not,
>> without trying to call it and try...except?
>>
>
> The following will do it:
>
> uses sysutils;
>
> Type
>   TParent = Class
> Procedure MyMethod; virtual; abstract;
>   end;
>
>   TChild = class(TParent)
>   end;
>
> var
>   C : TParent;
>
> begin
>   c:=TChild.Create;
>   If TMethod(@C.MyMethod).Code=**Pointer(@system.AbstractError) then
> Writeln('Not implemented')
>   else
> Writeln('Implemented')
> end.
>
> When run, it will print 'Not implemented'.
>
> But you should not instantiate objects with abstract methods to begin with.
>
> The compiler warns you if you do.
> (compile the above program with warnings/hints to see it)
>
> Michael.
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Dynamic library dependency error

2013-01-22 Thread Xiangrong Fang
Thanks,  I added -fPIC and it worked, it seems no need to add -dFPC_PIC?

Also I found a small problem.   While create a new shared library and
compile fpc always complain that -WR is invalid.   I have to uncheck
"Relocatable" option to fix this.

I think this is a bug in lazarus project template, what do you think?

2013/1/23 Antonio Fortuny 

>
>
> Le 22/01/2013 16:14, xrfang a écrit :
>
>> Hi Howard,
>>
>> Thanks for your info. Â After adding LCLBase to dependencies, I get these
>> errors:
>>
>>
>> /usr/bin/ld: warning: link.res contains output sections; did you forget
>> -T?
>> /usr/bin/ld: /home/xrfang/Desktop/**paintrect/lib/x86_64-linux/**paintrect.o:
>> relocation R_X86_64_32S against `_$PAINTRECT$_Ld1' can not be used when
>> making a shared object; recompile with -fPIC
>> /home/xrfang/Desktop/**paintrect/lib/x86_64-linux/**paintrect.o: æ—
>> æ³•è¯»å –ç¬¦å ·: 错误的值
>>
>> liboval.lpr(14) Error: Error while linking
>>
>> where "æ— æ³•è¯»å –ç¬¦å ·: 错误的值" means "cannot read symbol:
>> illegal value".
>>
>> What's wrong here?
>>
>>  Try adding
> -fPIC
> -dFPC_PIC
> into program's options, Other section
> Tha's what I use when building shared libraries.
>
> Antonio.
>
>
>
>
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] record literal in FPC?

2013-01-08 Thread Xiangrong Fang
Hi leledumbo,

As far as I know pascal inline directive only affect the compiler, not how
you write code. Could you please give an example how inline function helps
in my question?

Thanks

2013/1/9 leledumbo 

> If you declare an inline function producing the record, the effect would be
> the same with that literal record.
>
>
>
> --
> View this message in context:
> http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-record-literal-in-FPC-tp4028464p4028474.html
> Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com.
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Can a C++ program use a freepascal object?

2012-06-06 Thread Xiangrong Fang
I know this, just wanted to share fpc object with cpp .  ::-)
在 2012-6-6 下午10:46,"leledumbo" 写道:

> Yes, using C style procedural interface. You have to (un)wrap the object
> oriented code on both sides.
>
> --
> View this message in context:
> http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Can-a-C-program-use-a-freepascal-object-tp4024363p4024368.html
> Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com.
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Can a C++ program use a freepascal object?

2012-06-06 Thread Xiangrong Fang
Hi,

I am playing with CURL in FPC.  My question is, if I write a wrapper for
curl, e.g. TEasyCURL, is it possible to put this class into a shared
library and let a C++ program use it (either static or dynamic link)?

Thanks,
Shannon
--
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] torry for lazarus?

2012-06-05 Thread Xiangrong Fang
Hi,

Is there a site like www.torry.net for lazarus?

--
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Canvas size mismatch with control size

2012-06-05 Thread Xiangrong Fang
Hi,

I found that on Windows platform, Canvas size may mismatch with control's
size.  See the following code:

procedure TForm1.FormPaint(Sender: TObject);
begin
  Caption := Format('Form=%d:%d, Canvas=%d:%d', [Width, Height,
Canvas.Width, Canvas.Height]);
end;

Run this code on Windows, I found that when the form is enlarged, the 2
sizes matches, but when the form shrinks Canvas' size is always the largest
value it has been.

--
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] A few questions

2012-06-03 Thread Xiangrong Fang
More info about the bug I reported:

I installed Laz1.1/win32 on Ubuntu via wine, the problem does NOT exist on
wine platform. I also confirmed that the same problem appear on a physical
Win7 machine, so it is not my virtualbox's fault.

Shannon

2012/6/2 Xiangrong Fang 

> Hi Mattias,
>
> 1) About Laz on Ubuntu 12.04:  it is quite OK, except that the installing
> process is still very tricky and after install it has 2 minor problems:
>
> - on first start, it always complains that FPC source is not found.
> - on program termination (if run within the IDE), the attached error is
> shown.
>
> 2) About the bug I reported. I confirm that it does NOT appear on Ubuntu,
> but only Windows. And it appears on both Win7 and WinXP, both laz v0.9.30.4
> and the bleeding edge nightly build.
>
> 3) I used the correct form of FloodFill, now the compiler is happy, but
> there is no flood fill at all (both on windows and linux).  btw, to make
> sure I use it correctly, I just need to specify a point within the shape I
> want to fill, right?
>
> Shannon
>
>
> 2012/6/2 Mattias Gaertner 
>
>> On Sat, 2 Jun 2012 09:16:54 +0800
>> Xiangrong Fang  wrote:
>>
>> > Hi There,
>> >
>> > I've been away from Laz for a few months.  And just tried the daily
>> build
>> > on Windows. Now having a few questions:
>> >
>> > 1) How is the status of latest Lazarus on Ubuntu?   I had very bad
>> > experience during Ubuntu 11.04 and 11.10, notable problem is Laz does
>> not
>> > play well with Unity global menu.
>>
>> Can you be more specific?
>>
>>
>> >[...]
>> > 3)  I tried to use TCanvas.FloodFill, but compiler told me incorrect
>> number
>> > of arguments. I traced down into the fpcanvas source, the signature is
>> > correct, I wonder if that method is implemented or not?
>>
>> The FPCanvas.FloodFill(x,y) is not implemented in the LCL. It
>> "reintroduces" another FloodFill(X, Y: Integer; FillColor: TColor;
>> FillStyle: TFillStyle). This means the compiler message is correct.
>>
>> The "find declaration" ignores the "reintroduce" and finds more than
>> the compiler.
>>
>> Just add the two parameters.
>>
>> Keep in mind that FloodFill can be very slow.
>>
>> Mattias
>>
>> --
>> ___
>> Lazarus mailing list
>> Lazarus@lists.lazarus.freepascal.org
>> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>>
>
>
>
> --
>
>
>


--
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Undefined identifier: RequireDerivedFormResource

2012-06-03 Thread Xiangrong Fang
ok, since this is a new feature, why it report "variable not defined"? I
guess there are some version mismatch among lazarus, lcl or the bundled fpc.

What do you think?

2012/6/2 leledumbo 

>
> http://lists.lazarus.freepascal.org/pipermail/lazarus/2011-February/060229.html
>
> --
> View this message in context:
> http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Undefined-identifier-RequireDerivedFormResource-tp4024284p4024286.html
> Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com.
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>



--
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Undefined identifier: RequireDerivedFormResource

2012-06-01 Thread Xiangrong Fang
in the project main file, the following line is added (not by me):

RequireDerivedFormResource := True;

But while compiling it tell me this identifier is not defined. What's this
for?

Thanks,
Shannon
--
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] A few questions

2012-06-01 Thread Xiangrong Fang
Hi Mattias,

1) About Laz on Ubuntu 12.04:  it is quite OK, except that the installing
process is still very tricky and after install it has 2 minor problems:

- on first start, it always complains that FPC source is not found.
- on program termination (if run within the IDE), the attached error is
shown.

2) About the bug I reported. I confirm that it does NOT appear on Ubuntu,
but only Windows. And it appears on both Win7 and WinXP, both laz v0.9.30.4
and the bleeding edge nightly build.

3) I used the correct form of FloodFill, now the compiler is happy, but
there is no flood fill at all (both on windows and linux).  btw, to make
sure I use it correctly, I just need to specify a point within the shape I
want to fill, right?

Shannon

2012/6/2 Mattias Gaertner 

> On Sat, 2 Jun 2012 09:16:54 +0800
> Xiangrong Fang  wrote:
>
> > Hi There,
> >
> > I've been away from Laz for a few months.  And just tried the daily build
> > on Windows. Now having a few questions:
> >
> > 1) How is the status of latest Lazarus on Ubuntu?   I had very bad
> > experience during Ubuntu 11.04 and 11.10, notable problem is Laz does not
> > play well with Unity global menu.
>
> Can you be more specific?
>
>
> >[...]
> > 3)  I tried to use TCanvas.FloodFill, but compiler told me incorrect
> number
> > of arguments. I traced down into the fpcanvas source, the signature is
> > correct, I wonder if that method is implemented or not?
>
> The FPCanvas.FloodFill(x,y) is not implemented in the LCL. It
> "reintroduces" another FloodFill(X, Y: Integer; FillColor: TColor;
> FillStyle: TFillStyle). This means the compiler message is correct.
>
> The "find declaration" ignores the "reintroduce" and finds more than
> the compiler.
>
> Just add the two parameters.
>
> Keep in mind that FloodFill can be very slow.
>
> Mattias
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>



--
<>--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] A few questions

2012-06-01 Thread Xiangrong Fang
Hi There,

I've been away from Laz for a few months.  And just tried the daily build
on Windows. Now having a few questions:

1) How is the status of latest Lazarus on Ubuntu?   I had very bad
experience during Ubuntu 11.04 and 11.10, notable problem is Laz does not
play well with Unity global menu.

2) There is a problem with Canvas, I reported a bug already (
http://bugs.freepascal.org/view.php?id=22163)  Please create a new project,
add an Form.OnPaint event handler:

procedure TForm1.FormPaint(Sender: TObject);
begin
  with Canvas do begin
Pen.Width:=1;
Pen.Color:=clRed;
MoveTo(0, 0);
LineTo(100, 0);
LineTo(0, 100);
LineTo(0, 0);
MoveTo(Width - 1, Height - 1);
LineTo(Width - 101, Height - 1);
LineTo(Width - 1, Height - 101);
LineTo(Width - 1, Height - 1);
  end;
end;

While the program is running there are two triangles on the top left and
bottom right corner of the form.  Now you maximize the form, the 2
triangles are redrawn. But then you restore the form, the bottom triangle
is NOT drawn!

3)  I tried to use TCanvas.FloodFill, but compiler told me incorrect number
of arguments. I traced down into the fpcanvas source, the signature is
correct, I wonder if that method is implemented or not?

Thanks!
Shannon

--
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] startup problem

2011-02-23 Thread Xiangrong Fang
Hi Mattias,

The key problem is that I did NOT compile it myself, I downloaded the amd64
deb from the daily snapshot page.  There was no fpc or lazarus on the ubuntu
(2 machines) before I install snapshot 20110222.

How do I update individual files? Also, isn't it a bug that the snapshot
included some old files?

Sincerely,
Shannon

2011/2/23 Mattias Gaertner 

>
>
>
> Xiangrong Fang  hat am 23. Februar 2011 um 11:42
> geschrieben:
>
>
>  LCLBase 1.0, *not* 1.01, but under that, FCL is at 1.0.1
>
>
>
>   Check via the Package / Package Graph what lclbase.lpk file is used and
> if it is 1.0.1.
>
>
>
>   Maybe you have some old files?
>
>
>  You have some old files.
>  Please update.
>   Mattias
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] startup problem

2011-02-23 Thread Xiangrong Fang
Hi Mattias,

LCLBase 1.0, *not* 1.01, but *under that*, FCL is at 1.0.1

Sincerely,
Shannon

2011/2/23 Mattias Gaertner 

>
>
>
> Xiangrong Fang  hat am 23. Februar 2011 um 09:54
> geschrieben:
>
>
>  Hi Mattias,
>  I confirm that the file is installed on this path:
>   /usr/lib/lazarus/0.9.31/lcl/units/x86_64-linux/registerlcl.{o|ppu}
>   But lazarus still complain that it cannot find that unit on startup.
>
>
>
> Check via the Package / Package Graph what lclbase.lpk file is used and if
> it is 1.0.1.
>
>
>
> Mattias
>
>
>
>
>  2011/2/23 Mattias Gaertner 
>
>  On Wed, 23 Feb 2011 12:26:07 +0800
> Xiangrong Fang  wrote:
>
> > Hi,
> >
> > While I start lazarus it pops up a box saying:
> >
> > Package: "LCLBase 1.0"
> > Unit Name: "RegisterLCL"
> > Unit not found: "RegisterLCL"
>
> The current version is "LCLBase 1.0.1" and it has the unit registerlcl.
>
>
> > This happens on Linux x64 platform and on several recent releases of
> lazarus
> > 0.9.31 (e.g.  svn daily snapshot 20110222).
> >
> > Is there a bug or it is a configuration problem I can fix?
>
> Maybe you have some old files?
>
> Mattias
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] startup problem

2011-02-23 Thread Xiangrong Fang
Hi Mattias,

I confirm that the file is installed on this path:

/usr/lib/lazarus/0.9.31/lcl/units/x86_64-linux/registerlcl.{o|ppu}

But lazarus still complain that it cannot find that unit on startup.

2011/2/23 Mattias Gaertner 

> On Wed, 23 Feb 2011 12:26:07 +0800
> Xiangrong Fang  wrote:
>
> > Hi,
> >
> > While I start lazarus it pops up a box saying:
> >
> > Package: "LCLBase 1.0"
> > Unit Name: "RegisterLCL"
> > Unit not found: "RegisterLCL"
>
> The current version is "LCLBase 1.0.1" and it has the unit registerlcl.
>
>
> > This happens on Linux x64 platform and on several recent releases of
> lazarus
> > 0.9.31 (e.g.  svn daily snapshot 20110222).
> >
> > Is there a bug or it is a configuration problem I can fix?
>
> Maybe you have some old files?
>
> Mattias
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] startup problem

2011-02-22 Thread Xiangrong Fang
Hi,

While I start lazarus it pops up a box saying:

Package: "LCLBase 1.0"
Unit Name: "RegisterLCL"
Unit not found: "RegisterLCL"

This happens on Linux x64 platform and on several recent releases of lazarus
0.9.31 (e.g.  svn daily snapshot 20110222).

Is there a bug or it is a configuration problem I can fix?

Thanks,
Shannon
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


  1   2   >