Board index » delphi » OOP isn't so hard

OOP isn't so hard

Quote
Alessandro Federici wrote:
> ROTFLMAO!!!
> I've always been struggling with that too but settled on the Delete at the
> end!!!!
> The Delete still bugs me anyways. I'd like to avoid it but there's no way I
> could find to do it
> ni a faster way. The IFs that you require would just slow the thing down too
> much.

well,that code wasn't really fast anyway... you are relocating the
memory in the string each time. This is much more time consuming than
all the ifs you could add ;-)

On this case it doesn't matter but if you have many strings, counting
the total size and then doing a SetLength(s, totalsize) can speed things
A LOT.

BTW, is this delete approach that much beter than

    Result := TJob(FJobList[0]).GetJobName();
    for i := 1 to FJobList.Count-1 do
         Result := ', '+Result;

Not that many ifs, and 1 line less ;-)

 

Re:OOP isn't so hard


Adrian Gallero <agall...@netscape.net> wrote in
news:3e6fab56$1@newsgroups.borland.com:

Quote
>     Result := TJob(FJobList[0]).GetJobName();
>     for i := 1 to FJobList.Count-1 do
>          Result := ', '+Result;

I think you would end up with a comma as the first character.

maybe you meant

result := result + ',' + FJobList[i].GetJobName();

--
Iman

There appear to be absolutely no rules in Hollywood. It is anarchy.
Hollywood is essentially Thunder Dome with fake {*word*12}. - Peter DeWolf

Re:OOP isn't so hard


Quote
Iman L Crawford wrote:
> Adrian Gallero <agall...@netscape.net> wrote in
> news:3e6fab56$1@newsgroups.borland.com:

>>    Result := TJob(FJobList[0]).GetJobName();
>>    for i := 1 to FJobList.Count-1 do
>>         Result := ', '+Result;

> I think you would end up with a comma as the first character.

> maybe you meant

> result := result + ',' + FJobList[i].GetJobName();

uppsss.... bad copy/paste. but you got the idea.

Re:OOP isn't so hard


Quote
>> result := result + ',' + FJobList[i].GetJobName();

> uppsss.... bad copy/paste. but you got the idea.

don't even know why I used GetJobName() instead of GetJobName; :-)

Ps: I don't want to start a war about if we should use () to function
calls or not.

Re:OOP isn't so hard


How about:

procedure TPiddyJob.AddOccupations(T, P, B : boolean);
  begin
     with PiddyJobs do  begin
       JobCount := Byte(T);
       Inc(JobCount, Byte(P));
       Inc(JobCount, Byte(B));
     end;
  end;

Is Boolean still stored as Byte? This is bad coding, looks horrendous. May
even cause problems. But, I just thought it would be fun.

Re:OOP isn't so hard


Quote
"Alessandro Federici" <alef@[nospam]remobjects.com> wrote in message

news:3e6f8c99$1@newsgroups.borland.com...

Quote
> "DRS" <d...@removethis.ihug.com.au> wrote in message
> news:3e6f889a@newsgroups.borland.com...

> > Shouldn't that be "if (i in Value) then"?

> yeah yeah, slipped out during the refactoring <G>

Please report to the manager's office, ASAP.

Re:OOP isn't so hard


Adrian Gallero <agall...@netscape.net> wrote in
news:3e6fada3$1@newsgroups.borland.com:

Quote
> Ps: I don't want to start a war about if we should use () to function
> calls or not.

I didn't even notice.  :)

--
Iman

There appear to be absolutely no rules in Hollywood. It is anarchy.
Hollywood is essentially Thunder Dome with fake {*word*12}. - Peter DeWolf

Re:OOP isn't so hard


Quote
"Adrian Gallero" <agall...@netscape.net> wrote in message

news:3e6fab56$1@newsgroups.borland.com...

Quote
>     for i := 1 to FJobList.Count-1 do
> Not that many ifs, and 1 line less ;-)

Brilliant in its simplicity.

Re:OOP isn't so hard


Quote
"richk" <richk@_nospam_alltel.net> wrote in message

news:3e6faf06@newsgroups.borland.com...

Quote
> Is Boolean still stored as Byte?

Works. I use it from time to time. It's a nanosecond faster <G>

Re:OOP isn't so hard


Quote
"Alessandro Federici" <alef@[nospam]remobjects.com> wrote in message

news:3e6f9274$1@newsgroups.borland.com...

Quote
> 4) How much time did you spend looking at the VCL code which uses code
that
> is virtually identical to what I used
> in my sample?

Well, now... I can say that Delphi is GREAT. But, I don't know if I would
consider VCL code to be the STANDARD for all code to be judged by.

Re:OOP isn't so hard


"Iman L Crawford" <ilcrawford.at.hotmail.dot.com> wrote in message
news:Xns933CA1D4DA6Cilcrwfrd@207.105.83.65...

Quote
> Here's a simple example from Learning Python

> def factory(aClass, *args):
>   return apply(aClass, args)

> class Spam:
>   def doIt(self, message):
>     print message

> class Person:
>   #__init__ is called when an object is created
>   def __init__(self, name, job):
>     self.name = name
>     self.job = job

> object1 = factory(Spam)
> object1.doIt('Test') #prints test to the stdout

> object1 = factory(Person, "Guido", "guru")
> print object1.name #prints "Guido to the stdout

#p___ 45 + 98/10 &^&%$ = 15
Go to page: [1] [2] [3] [4] [5] [6] [7] [8]

Other Threads