Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 02/10/19 in all areas

  1. Dalija Prasnikar

    Pitfalls of Anonymous methods and capture

    To be honest, knowing the type of Handler.OnHandle is crucial for understanding the issue. The other implementation details don't matter as much. Broker.AddHandler(Handler.OnHandle); And usually I don't go around and download code examples, just to get to the bottom of some problem. Only under special circumstances - mostly from bugs reported in QP, when having complete test project is crucial for reproducing the issue. The only reason, why I did go and download this example is because I know you. So whether you like it or not, David does have a point.
  2. Remy Lebeau

    First!

    I'm here!
  3. David Heffernan

    Pitfalls of Anonymous methods and capture

    It's an extra step for every one of your readers. In fact it's multiple steps. Down file. Unzip file. One goal of the writer is to make it easier for the reader to see and understand. For instance, if I was on a mobile device how would I read files in a zip file?
  4. dummzeuch

    Two GExperts bugs fixed, 14 to go

    I just fixed two (newly reported) bugs in GExperts: The Set Tab Order dialog no longer worked in Delphi 6, 7 and 2005. This was due to me adding AlignWithMargins (and the associated Margins property) to the dfm file. This property apparently was introduced in Delphi 2006. Again, this underlines what I mentioned several times: I do not use Delphi < 2007 for anything but testing and fixing bugs GExperts. That’s why glitches like this tend to slip by unnoticed. That’s why I would like people to volunteer for testing the various versions. But apparently nobody can be bothered. Fine by me, but you will have to live with the consequences. I don’t have a QA department. The extensions to the Uses Clause Manager caused several thousand (small) files to be created in the GExperts configuration directory. This directory is located under AppData\roaming\GExperts which means it will be copied when roaming profiles are enabledin a Windows domain. I didn’t know that anybody still uses roaming profiles since they are usually not worth the trouble, but apparently they are still being used. So I now moved that cache to AppData\local and also added a config option to disable caching altogether. https://blog.dummzeuch.de/2019/02/09/two-gexperts-bugs-fixed-14-to-go/
  5. Mahdi Safsafi

    How to switch condition position?

    Don't worry everything is gonna be alright by the time. When I was beginner I asked a similar question : what's the purpose of interface. I got many answers but it took me a lot of time to understand what they were saying. Here is a free advice : first get familiar about the basic of program's life from the loader-time to the cpu-time (just get the basic things) and then master the fundamental stuff of Delphi (also just learn the basic things : statements, functions, array, records, RTL, ...). Now join the open source community and share your first library/app, fork other project and analyse people coding styles (it will be a great experience to you as was mine). after that you will find yourself understanding things quickly even you can master new language with just few days. Good Luck.
  6. Mahdi Safsafi

    How to switch condition position?

    Well Mike. This is our community. They're all exited and each topic turns just like this one xD ... All people here love coding ... and I'm sure you will love this community too. You said your're a new to Delphi. We welcome you here 🙂. Now for your question about using "Result := Value if(Condition);" , the sort answer is not possible. I believe that using table lookup is match easy for you: type TRec = record Patterns: array of string; Result: string; end; PRec = ^TRec; const Table: array [0 .. 1] of TRec = ( (Patterns: ['Prop1', 'Prop2', 'Prop3', 'Prop4', 'Prop5', 'Prop6', 'Prop7']; Result: 'N'), (Patterns: ['PropertyA', 'PropertyB', 'PropertyC', 'PropertyD']; Result: 'DefaultABC') ); function LookUp(const AProperty: string): string; var I: Integer; Rec: PRec; begin for I := 0 to Length(Table) - 1 do begin Rec := @Table[I]; if (MatchStr(AProperty, Rec^.Patterns)) then exit(Rec^.Result); end; Result := 'Default'; end; Because you're a new to Delphi, I believe that's the best way for you right now. Later you can optimise it by using binary string search, hash-code, magic-index, crc32 and binary lookup, ...
  7. if Condition then Result := True; Result := Condition; These are not the same! What if Result is true before that line in the first and in the second case?
  8. David Heffernan

    How to switch condition position?

    Seems kind of a waste of time this entire discussion. The language is well documented and is quite concise. The are only a handful of conditional statements. The syntax for if is clear. You have to write the code in the language that is provided to you. Use an if statement. End of story.
  9. KeithLatham

    How to switch condition position?

    Huh, yeah like Rudy said, how about Result := (condition) So your example if Property = 'A' then Result := 'N'; becomes Result := { start anonymous method } function(old, test, new: string) : string begin Result := old; if old := test then result := new; end; { end anonymous method } NO. anonymous method bad (IMHO) Much better is: function tester(old, test, new: string) : string; begin Result := old; if old := test then result := new; end; and then call it like function domything : string; begin {do something to establish the initial value of result} Result := tester(result, 'A', 'N'); end; Fundamentally, you are trying to do something that just is not in the syntax of the language. The designer(s) of the Pascal language made syntax choices that give the language its 'flavor'. Other designers gave other languages different syntax because it appealed to them or they saw 'easy' ways to implement them or whatever. It is pointless to choose an implementation language and then bang against the design choices inherent in that language. If you are used to something working one way in one language that you don't see in Pascal, then you need to understand that you are now working in Pascal, not in that other language. Your goal is not to write a program that 'looks like a similar program in language X'; your goal is to solve a problem in the language you're are working with. EVERY language whether it is Pascal, Perl, Python, Lisp, Cobol, APL, Fortran, Simula, Visual Basic, or anything else has constructs to accomplish your goal. But they all look differently when they do it, and that is what makes them different from one another.
  10. Dalija Prasnikar

    First!

    Really nice to see you here.
  11. Write your own procedure: procedure MPC(var Result: string; const Value: string; Condition: Boolean); // MPC stands for Mike's Preferenced Condition begin if Condition then Result := Value; end; ... // call MPC(Result, 'N', Property = 'A'); You can even make it a function, but then you must provide a value for the false condition, too.
×