Ted Lyngmo

Member since: Wednesday, 06 September 2017
Last login: 3 hours 9 minutes ago
Profile viewed: 176 views

No Rank
Points: 0

Ted Lyngmo replied to the topic 'Compiler bug / How to enable ASM output in a .cbproj file' in the forum. 3 hours 56 minutes ago

Alan wrote: If I turn on debugging and/or codeguard the code works fine. If I turn off codeguard and go for release, it fails to work fine. Tested in both old bcb6 and c++builder in rad studio 10.2, both exhibit the behavior. Both mem1 and c1 are defined as uint8_t.

Perhaps some optimization makes it skip the loop.
I doubt this is how mem1 is defined:
uint8_t mem1;
Perhaps one of these?
uint8_t mem1[256];
std::array<uint8_t, 256> mem1;
std::vector<uint8_t> mem1(256);
Please show the actual definition and how they are initialized before the loop is entered.

Alan wrote: I have some code that is meant to move forward until it finds the first mem1[c1] that is not true.

while (mem1[c1])
  c1++;

Can you guarantee that there will be at least one position in mem1[] == 0 when you enter that loop or is the mem1 array volatile and written to by another thread? What's the output if you do something like this:
while(mem1[c1]) ++c1;
std::cout << "c1=" << static_cast<int>(c1) << " mem1[c1]=" << static_cast<int>(mem1[c1]) << "\n";

Br,
Ted

Read More...

Ted Lyngmo replied to the topic 'Undeclared identifier 'TNetResource' in FMX' in the forum. 12 hours 50 minutes ago

I don't know if Indy has some implementation of the Neighbor Discovery Protocol (IPv6) or the IPv4 counterparts (ARP etc) - but f I understand TIdIPWatch correctly, it's for keeping track of your local computer's online status and the history of IP addresses issued to it during the lifetime of the TIdIPWatch instance. It won't help in this case.

TIdTCPClient is used for connecting to a known TCP server+port. You can use it for scanning random hosts+ports in your LAN but it's probably not what you want since you won't find all machines and it'll be time consuming.

What you probably are looking for is a component or API that'll implement one or more protocols in the Data link and/or Network layer ( OSI model ) to discover the machines and present interesting info about them, but I don't know any, and I don't know what set of protocols Windows uses to collect the resources returned by WNetOpenEnum or what protocols IP Scanner Pro uses to find devices. Now I got a little curious about this myself so I hope someone has some interesting idea.:-)

Read More...

Happy you got that sorted out!

A linker running out of memory is a joke - and having to deal with this for so many generations of the product is a joke on us, the customers.

That being said, can anything be done to help the linker? My units are usually very small and contain very little code combined with the VCL/FMX framework. So I've got one small unit to do one thing and I've never had the linker running out of memory.

Would it be possible to break you code down into smaller compilable pieces to see how the linker deals with them?

Read More...

Ted Lyngmo replied to the topic 'GetGattServer causes access violation / Bluetooth LE' in the forum. 4 days ago

Ok. If you can, verify that the Android API is broken by using their recommended toolchain. If it's not, file a report with Embarcaderos QC.

Read More...

Ted Lyngmo replied to the topic 'App crashes with Android 7' in the forum. 4 days ago

How far have you come debugging the issue?
Do you have any code you can share?

It's very hard to just guess what kind of problem you've come across.

Read More...

Ted Lyngmo replied to the topic 'Missing error function erf()' in the forum. 4 days ago

Many thanks for trying it out. It's a shame they've left the math parts out. What about the std::char_traits not being C++11 compliant?
In 10.2.1 this does not compile because std::char_traits<char> is not a constexpr, but according to the standard, it is.

switch(something) {
    case std::char_traits<char>::eof():
    // do something 
}


Read More...

Ted Lyngmo replied to the topic 'Datasnap rest special characters' in the forum. 5 days ago

Please show the code where the problems become obvious.
I haven't used datasnap myself, but it seems to be based on JSON and JSON strings are UTF8 encoded. Perhaps you have used a string type somewhere where that information is lost?

Read More...

Ted Lyngmo replied to the topic 'GetGattServer causes access violation / Bluetooth LE' in the forum. 6 days ago

Strange. I made a test program with a BluetoothLE component that I dropped on the main form an also with a pointer to the TBluetoothLEManager. When I press a button it prints to a memo:

void __fastcall THeaderFooterForm::Button1Click(TObject *Sender)
{
	TBluetoothLEManager* lem = TBluetoothLEManager::Current;

	mem->Lines->Add( ble->SupportsGattServer );
	mem->Lines->Add( lem->SupportsGattServer );
}

It prints 0 and 1 ... I don't know if that makes any sense?

Read More...

Ted Lyngmo replied to the topic 'Missing error function erf()' in the forum. 6 days ago

Hi Greg!

I'm using 10.2.1 and have the same problem using std::erf() and many other standard C++11 functions from <cmath>.

I wrote this ticket about it:
RSP-20789: A lot of <cmath> functions do no exist

When I let the IDE find the definition for std::erf() it shows this:

#define _GENERIC_MATH1(FUN, CRTTYPE) \
extern "C" _CHECK_RETURN CRTTYPE double _CDECL FUN(double); \
template<class _Ty> inline \
	typename _STD enable_if< _STD is_integral<_Ty>::value, double>::type \
	FUN(_Ty _Left) \
	{ \
	return (_CSTD FUN((double)_Left)); \
	}

_GENERIC_MATH1(erf, _CRTSPECIAL)
It looks like they tried getting it in anyway :-)

Is std::signbit() and std::isfinite() available in 10.2.3? I've had to make my own implementations of the functions I need to be able to use 3pp libs that rely on them :-/

Br,
Ted

Read More...

Ted Lyngmo replied to the topic 'Rotating Timage' in the forum. 6 days ago

I've got something that works for VCL but it's perhaps a very clumsy way of doing it. I use the PlgBlt function so it's pretty fast.

The main function looks like this:

void BitmapRotate(TBitmap* out, TBitmap* in, double radians);
You are welcome to try it out.

BitmapRotate.h
//---------------------------------------------------------------------------
#ifndef BitmapRotateH
#define BitmapRotateH
#include <Vcl.Graphics.hpp>
#include <Vcl.Imaging.jpeg.hpp>
#include <Vcl.Imaging.GIFImg.hpp>
//---------------------------------------------------------------------------

// Silly helper classes to be able to LoadFromFile() and then Draw() to a TGraphic
// instead of using Assign().
class TJpegImageWithDraw : public TJPEGImage {
public:
	using TJPEGImage::TJPEGImage;
	// 	virtual void __fastcall Draw(Vcl::Graphics::TCanvas* ACanvas, const System::Types::TRect &Rect);
	using TJPEGImage::Draw;
};

class TGIFImageWithDraw : public TGIFImage {
public:
	using TGIFImage::TGIFImage;
	// 	virtual void __fastcall Draw(Vcl::Graphics::TCanvas* ACanvas, const System::Types::TRect &Rect);
	using TGIFImage::Draw;
};

template <typename T>
// LoadFromFileToPicture<TJpegImageWithDraw>(src_file, dest_picture);
// LoadFromFileToPicture<TGIFImageWithDraw>(src_file, dest_picture);
void __fastcall LoadFromFileToPicture(const System::UnicodeString Filename, TPicture* Picture) {
	std::unique_ptr<T> compressed(new T());
	compressed->LoadFromFile(Filename);

	std::unique_ptr<TBitmap> bmp(new TBitmap());
	bmp->SetSize(compressed->Width, compressed->Height);
	compressed->Draw(bmp->Canvas, TRect(0,0,compressed->Width,compressed->Height));

	Picture->Graphic = bmp.get();
}

// useful conversions
inline double DegreesToRadians(double deg) { return deg*M_PI/180.0; }
inline double RadiansToDegrees(double rad) { return rad*180.0/M_PI; }

// The actual rotating function - make sure you have a real "in" bitmap, not a
// JPEGImage or TGIFImage representation. Use the LoadFromFileToPicture<>
// function if you need it.
//
// The "out" bitmap will scale to fit the rotated picture and the background
// will be filled using the current Brush of the out bitmap.
void BitmapRotate(TBitmap* out, TBitmap* in, double radians);

#endif
BitmapRotate.cpp
//---------------------------------------------------------------------------
#include <cmath>
#include <algorithm>
#include <memory>
#include <Windows.h>
#pragma hdrstop

#include "BitmapRotate.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
struct TDoublePoint {
	double x;
	double y;
};
//---------------------------------------------------------------------------
struct TRotatingPoint : public POINT {
	TRotatingPoint() : POINT{0,0} {}
	TRotatingPoint(LONG x, LONG y) : POINT{x,y} {}
	TRotatingPoint& operator=(const POINT& rhs) {
		x = rhs.x;
		y = rhs.y;
		return *this;
	}
	void Rotate(const TDoublePoint& origo, double radians) {
		// must be normalized after rotation
		double X = static_cast<double>(x) - origo.x;
		double Y = static_cast<double>(y) - origo.y;
		double length =
			std::sqrt(
				std::pow(X, 2.0) +
				std::pow(Y, 2.0)
			);
		radians = std::atan2(Y,X)-radians;
		x = std::round( std::cos(radians) * length );
		y = std::round( std::sin(radians) * length );
	}
};
//---------------------------------------------------------------------------
class TParallelogram {
private:
	TRotatingPoint points[4]; // one more than needed - could be calculated instead
public:
	TParallelogram(const POINT& upper_left, const POINT& upper_right,
				const POINT& lower_left, const POINT& lower_right)
	{
		points[0] = upper_left;
		points[1] = upper_right;
		points[2] = lower_left;
		points[3] = lower_right;
	}

	operator POINT* () { return points; }

	inline TRotatingPoint& upper_left() { return points[0]; }
	inline TRotatingPoint& upper_right() { return points[1]; }
	inline TRotatingPoint& lower_left() { return points[2]; }
	inline TRotatingPoint& lower_right() { return points[3]; }
	// lower_right could be calculated. From MSDN PlgBlt doc:
	// The fourth vertex of the parallelogram (D) is defined by
	// treating the first three points (A, B, and C ) as vectors
	// and computing D = B +CA.

	inline LONG MinX() {
		return std::min({upper_left().x, upper_right().x,
					lower_left().x, lower_right().x});
	}
	inline LONG MaxX() {
		return std::max({upper_left().x, upper_right().x,
					lower_left().x, lower_right().x});
	}
	inline LONG MinY() {
		return std::min({upper_left().y, upper_right().y,
					lower_left().y, lower_right().y});
	}
	inline LONG MaxY() {
		return std::max({upper_left().y, upper_right().y,
					lower_left().y, lower_right().y});
	}
	inline LONG Width() {
		return MaxX()-MinX();
	}
	inline LONG Height() {
		return MaxY()-MinY();
	}

	void Rotate(double radians) {
		// center
		TDoublePoint origo{static_cast<double>(Width()) / 2.0,
				static_cast<double>(Height()) / 2.0};

		// rotate
		for(auto& pt : points) {
			pt.Rotate(origo, radians);
		}

		// normalize
		LONG norm_x = MinX();
		LONG norm_y = MinY();
		for(auto& pt : points) {
			pt.x -= norm_x;
			pt.y -= norm_y;
		}
	}
};
//---------------------------------------------------------------------------
void BitmapRotate(TBitmap* out, TBitmap* in, double radians) {
	TParallelogram par(POINT{0,0}, POINT{in->Width,0},
			POINT{0,in->Height}, POINT{in->Width,in->Height});

	par.Rotate(radians);
	// DeleteObject(out->ReleaseHandle()); // FillRect is nicer
	out->SetSize(par.Width(), par.Height());
	out->Canvas->FillRect(TRect(0,0,out->Width,out->Height));

	PlgBlt(out->Canvas->Handle, par,
		   in->Canvas->Handle, 0,0,
		   in->Width, in->Height,0,0,0);
}
//---------------------------------------------------------------------------

Br,
Ted

Read More...

Ted Lyngmo replied to the topic 'Undeclared identifier 'TNetResource' in FMX' in the forum. 7 days ago

Ok, then you need to find a similar API for IOS. Perhaps ZeroConf's DNS-SD protocol can work. It's developed by Apple and is apparently available for Windows too in case you'd like to make it portable. I've never used it myself though.

Read More...

Ted Lyngmo replied to the topic 'GetGattServer causes access violation / Bluetooth LE' in the forum. 7 days ago

The BlueToothGattServer is listed as available since Android API lvl 18 (OS version 4.3) so I agree that it should be available.

Yes, System.Bluetooth.TBluetoothGattServer lists Android as supported, but System.Bluetooth.TBluetoothLEManager.GetGattServer does not. Odd :-) Perhaps it's a mistake in the documentation.

Are you using a System.Bluetooth.TBluetoothLEManager? What does the SupportsGattServer property say?

Br,
Ted

Read More...

Ted Lyngmo replied to the topic 'Datasnap server: Could not load SSL library' in the forum. 7 days ago

Oh :-) Great that it worked!

Read More...

Ted Lyngmo replied to the topic 'Datasnap server: Could not load SSL library' in the forum. 7 days ago

So, the XE6 and Tokyo servers and the DLL:s are all 32 bit?

Can you confirm that the Tokyo server is actually loaded from the same directory where the DLL:s are? Can you get this executed at startup?

TCHAR module[_MAX_PATH+1];
GetModuleFileName(NULL, module, _MAX_PATH+1);
MessageBox(module, module, MB_OK);
(or whatever that would look like in Delphi)

Did you try IdOpenSSLSetLibPath() ?

Read More...

Ted Lyngmo replied to the topic 'GetGattServer causes access violation / Bluetooth LE' in the forum. 1 week ago

Calls to GetGattServer() on unsupported platforms raise an exception.
Call the SupportsGattServer() function first to check if your plattform does support it.

The help text says only OS X (10.9+) and iOS (6+) supports it so I don't think you'll have much luck with it on your Android device.

Br,
Ted

Read More...

Ted Lyngmo replied to the topic 'Undeclared identifier 'TNetResource' in FMX' in the forum. 1 week ago

TNetResource is just the Delphi name for the Windows C struct NETRESOURCE (from winnetwk.h) if I'm not mistaken.
I don't think it'll be useful on anything but Windows - but if you are compiling this for Windows, it should be available via

uses
  Windows;
Br,
Ted

Read More...

Ted Lyngmo replied to the topic 'Datasnap server: Could not load SSL library' in the forum. 1 week ago

Are you mixing 32 and 64 bit executables and DLL:s?
You could put the 32/64 bit DLL:s in different subfolders and then use the function

IdOpenSSLSetLibPath()
to point to the correct path depending on whether your exe is 32 or 64 bit.

Br,
Ted

Read More...