Blog

All Blog Posts  |  Next Post  |  Previous Post

Add AI superpower to your Delphi & C++Builder apps part 2: function calling

Today

TMS Software Delphi  Components

Image generated by Grok

After the AI introduction blog on basic completion, i.e. prompt & answer cycles with the LLM, here is the 2nd part on function calling. This is where things get really interesting for us Delphi & C++Builder developers! We can basically hook up Delphi or C++Builder code to the LLM to let the LLM intelligently execute our code or to give the LLM our data it can then further process. 


Integrating Function Calling with Cloud-Based LLMs Using TTMSFNCCloudAI

Large Language Models (LLMs) have become immensely powerful in reasoning, synthesis, and automation tasks. But their capabilities extend far beyond basic conversation—thanks to function calling. This transformative feature allows an LLM not only to understand natural language but to actively trigger predefined functions in your software.

In this post, we’ll explore what function calling is, why it’s such a significant step forward, and how you can easily integrate it into your own applications using the TTMSFNCCloudAI component from the TMS FNC Cloud Pack.


What is Function Calling?

At its core, function calling lets an LLM invoke external logic—like APIs or app-specific procedures—based on the user’s intent.

Rather than just generating text, the model can identify when a user request matches a known "tool" or "function," understand its parameters, and return a structured payload that your application can process. Your code then executes the appropriate function and sends the result back to the model, closing the loop between natural language and real-world action.

Imagine asking:

“What’s the weather in Tokyo?”

With function calling, the model recognizes this intent, fills in the required parameter (city: "Tokyo"), and triggers a predefined function like getWeather. Your app runs that function—perhaps calling a weather API—and returns the current forecast.


Why Is This So Powerful?

Function calling allows LLMs to:

  • Perform precise, structured tasks (like querying APIs or databases)

  • Maintain data security by avoiding hallucinations and only accessing defined functions

  • Enable multi-turn workflows, where the model interacts with tools and returns contextual follow-ups

  • Become part of real applications, not just chat interfaces

It bridges the gap between AI as a reasoning engine and AI as a smart assistant executing actual business logic.


Implementing Function Calling with TTMSFNCCloudAI

The TTMSFNCCloudAI component makes it incredibly easy to integrate function calling, abstracting away much of the complexity.

1. Define Tools and Parameters

Each tool represents a callable function. You add tools to the Tools collection of the TTMSFNCCloudAI component and define parameters for each one.

Here’s a minimal example:

pascal
var t: TTMSFNCCloudAITool; p: TTMSFNCCloudAIParameter; begin t := FFNCAI.Tools.Add; t.Name := 'getweather'; t.Description := 'get the weather for the specified city'; p := t.Parameters.Add; p.Name := 'city'; p.Description := 'parameter specifying the city'; p.&Type := ptString; end;

This creates a tool called getweather with one required parameter: city.  This is a simple example, but tool parameters can be a lot more complex. Multiple parameter's of different types can be added, parameters can be marked as required or not and you can even specify array parameters and define complex types for array elements. 

2. Respond to Tool Calls

When the LLM identifies a need to use a tool, the OnExecuteTool event is triggered. You implement this handler to execute your custom logic:

pascal
procedure TForm1.ExecuteTool(Sender: TObject; Args: TJSONObject; var Result: string); var city, weather: string; begin city := Args.GetValue<string>('city'); weather := CallWeatherAPI(city); Result := weather; end;

In this example, the LLM supplies the city name, your app calls a weather API, and returns the result—seamlessly integrating AI reasoning with your business logic.

Some more examples

Building further from the GetWeather tool that fetches the current weather conditions and provides it to the AI, now we could add a tool that is able to interact with a map in our Delphi application and put labels on the map. With just this additional tool provided to the LLM, we have an application where the AI can automatically interact with the map and place labels with current weather conditions. The map in this example is our own powerful service-abstract TMS FNC Maps using the Google Maps service.

This is the code to add the tool to TTMSFNCCloudAI that informs the LLM there is a function to add an array of labels on the map at a coordinate Lon,Lat and a string parameter Weather

pascal
t := TMSFNCCloudAI1.Tools.Add; t.Name := 'addweather'; t.Description := 'add a label with weather info on the map'; p := t.Parameters.Add; p.&Type := ptArray; p.Name := 'labels'; p.Description := 'label array'; p.ArrayType := ptObject; ap := p.ArrayProperties.Add; ap.Name := 'lon'; ap.Description := 'the longitude'; ap.&Type := ptNumber; ap := p.ArrayProperties.Add; ap.Name := 'lat'; ap.Description := 'the latitude'; ap.&Type := ptNumber; ap := p.ArrayProperties.Add; ap.Name := 'weather'; ap.Description := 'the weather for the label'; ap.&Type := ptString; t.OnExecute := TMSFNCCloudAI1ToolsArrayExecute;

The code for handling this function call is:

pascal
procedure TForm1.TMSFNCCloudAI1ToolsArrayExecute(Sender: TObject; Args: TJSONObject; var Result: string); var ja: TJSONArray; jo: TJSONObject; i: integer; lon,lat: double; title: string; rec: TTMSFNCMapsCoordinateRec; begin ja := TJSONArray(args.GetValue('labels')); for i := 0 to ja.Count - 1 do begin jo := TJSONObject(ja.Items[i]); lon := jo.GetValue<double>('lon'); lat := jo.GetValue<double>('lat'); title := jo.GetValue<string>('weather'); rec.Longitude := lon; rec.Latitude := lat; tmsfncmaps1.AddLabel(rec, title, gcRed, gcYellow); end; end;


The result for the command below can be seen on the map

"Add a label with the current weather conditions for Paris, Madrid and Lissabon"

TMS Software Delphi  Components



Another example is to use the LLM to convert natural language to SQL commands and have these executed via a Delphi TQuery component. To only thing needed here to help the LLM is inform the LLM what fields are in our databse. This can be done by adding a parameter-less tool that will add the fields displayed in a grid (TMS FNC DataGrid in this case) and a tool with one string parameter holding the SQL command to execute the it. Configuring the tools is all done at design-time without adding a single line of code!

TMS Software Delphi  Components


The handlers for these two tools are:

pascal
procedure TForm4.TMSFNCCloudAI1Tools0Execute(Sender: TObject; Args: TJSONObject; var Result: string); var i: integer; begin for i := 0 to TMSFNCDataGridDatabaseAdapter1.Columns.Count - 1 do begin if Result <> '' then Result := Result + ','; Result := Result + TMSFNCDataGridDatabaseAdapter1.Columns[i].FieldName; end; end; procedure TForm4.TMSFNCCloudAI1Tools1Execute(Sender: TObject; Args: TJSONObject; var Result: string); var sql: string; begin sql := Args.GetValue<string>('sql'); ADOQuery1.SQL.Text := sql; ADOQuery1.Active := true; ShowMessage('Generated SQL query:'#13#10+SQL); end;

With this tool provided, it is smart enough to convert the natural language to a SQL command and have it executed:

TMS Software Delphi  Components


More use cases?

It looks to me that the uses for this are more limited by our imagination than the tecnical details. I can't wait to hear your feedback about other innovative use cases for this technology. Be in touch and we'll be eager to assist you! 


Works Across Cloud LLM Providers
TMS Software Delphi  Components

This setup works with any supported LLM that includes function/tool calling capabilities—such as OpenAI, Claude, Gemini, Mistral, Ollama, Grok or DeepSeek. TTMSFNCCloudAI abstracts the provider differences and lets you focus on the tool logic! That is the power of TMS FNC Cloud Pack where you never worry about the nitty gritty details of the REST APIs behind it.


Conclusion

Function calling is a cornerstone of next-generation AI applications. It turns a passive model into an active collaborator—understanding, delegating, and executing tasks. With the TTMSFNCCloudAI component, implementing this is as easy as defining tools, adding parameters, and writing a bit of code in an event handler.

If you’re using LLMs in your application and haven’t yet explored function calling, now’s the time.

In upcoming articles, we’ll dive deeper into image processing AI, RAG, agents, MCP servers & clients.  
If you have an active TMS ALL-ACCESS license, you can now get also access to the first test version of TMS AI Studio that uses the TTMSFNCCloudAI component but also has everything on board to let you build MCP servers and clients. 
Register now to participate in this testing via this landing page.

TMS Software Delphi  Components



Bruno Fierens




This blog post has not received any comments yet.



Add a new comment

You will receive a confirmation mail with a link to validate your comment, please use a valid email address.
All fields are required.



All Blog Posts  |  Next Post  |  Previous Post