multiple ports?

steve
2012-09-09
2013-04-30
  • steve
    steve
    2012-09-09

    Hello, just discovered this component, intending to use it with D7.
    I want to have more than one port up and running. By putting a second port onto the design form I can get portA and portB and can quite happily send data out  but which port gets the benefit of the onrxchar event? It seems to be the first port you land on the design form so my query is how do you get that event for the second port?
    I suspect that this is trivial, wish there had been a dual port example. Any hints gratefully received.

     
  • Warren
    Warren
    2012-09-09

    Before your small mess becomes a big mess, why don't you start separating things out?

    The TComPort is not exactly ideal to put on a Form. Put it on a data module and connect the data module to the form.

    Now you want to run two copies of the same logic, on two different ports? Maybe now you want to have two completely separate instances of the data module, each with its own variables and state, and each with its own com port object, and all the bits that go with it.

    It sounds like you're inserting a new feature with a crowbar, and a hammer, instead of thinking about your design.  Just a quick hint. Hope it helps.

    Sounds for example, like you've got event handlers, and you're trying to connect up two TComPort RxChar event handlers to the same event, and then sharing a bunch of code that doesn't necessarily work very well when its all sharing everything.

    But since we can't see your code, you're going to have to debug your situation on your own.

    Lookup what Encapsulation and Object Oriented Programming means, versus  "big ball of mud" or "no design and no architecture, other than what I could hack together in five seconds without thinking much about it".

    Cheers.

    W

     
  • Arne Johansson
    Arne Johansson
    2012-11-14

    Do I create a problem?
    wpostma claims "The TComPort is not exactly ideal to put on a Form".
    For me it can't be easier than using it that way. I have an application with four ComPorts on the same form. What problems could I get into?
    I don't understand how to put it on a data module. What do you mean "data module"?